0

I have the following script

<script>
setTimeout(function() { window.location.reload(); }, 2000); // 2 seconds, e.g.

$('a:contains("13468100")').closest('tr').find('.fightActionInnerInner').click();
</script>

The page has an iframe on it. The script is supposed to search the contents of the iframe for any links which contain the number 13468100 and clicks the tr next to it with an id of 'fightActionInnerInner', refreshing the page every 2 seconds.

The refresh function works, but the script doesn't seem to click the link, even though I know it's there.

Also, I'd like to have an input box where the user can input what they require the script to search for. Example: if they want to search for a link containing "David", they can just type David into a text box and it amends the script.

This is the html I am asking the script to search

<td class="fightMobster">

<div>
    <a href="/profile.php?puid=5562089&formNonce=34947b8ffc73e8ceafabae71…94f&setTab1Badge=&h=2d55f5781bfe888b47d7f5c9dbc27df2f663347f">

        Lord Pookie

    </a>
</div>
<div>

    Lvl 212 Daywalker

</div>

</td>
<td class="fightSp"></td>

<td class="fightMobSize">

<span class="cash">
    <span style="white-space: nowrap;">
        <img width="15" height="14" style="padding-right:2px" src="http://static.storm8.com/zl/images/flesh.png?v=330"></img>

        15,300

    </span>
</span>

</td>
<td class="fightSpLg"></td>

<td class="fightAction">

<script>


            function fsb99995143() {
              var b=…

</script>
<a onclick="return fsb99995143();" href="/hitlist.php?tab=fight.php&action=fight&hitlistId=99995143&f…1b4b9390bee9a194f&h=284e4fe4946e6fb8af3a662f4583454eebc8bd23">
    <div class="fightActionInner">
        <div class="fightActionInnerInner">

            Attack

        </div>
AdamH
  • 121
  • 5
  • 15
  • Please show us the HTML, without it we have no idea if what you are trying to do is right or not. But from the text you said `fightActionInnerInner` is an id and not a class `find('#fightActionInnerInner')`. – Spencer Wieczorek Nov 04 '14 at 16:40
  • Make sure the tr you are wanting is above the anchor tag you are wanting in the HTML. Finding .closest searches UP through the DOM not down. – Keith Enlow Nov 04 '14 at 16:44
  • @SpencerWieczorek I updated the post :) – AdamH Nov 04 '14 at 16:47

1 Answers1

0

I think a better more simple search query for it would be:

$(".fightActionInnerInner a:contains('13468100')").click();

This would do what you are describing from your script. It would find all tr with that class (I think you meant class not Id but just change the . to a # if you really wanted an Id) that has a link as a child containing whatever you want.

To make it custom you need to add a variable:

var name = $("#INPUT_ID").val();

and then append it to your query:

$(".fightActionInnerInner a:contains('" + name + "')").click();
Keith Enlow
  • 924
  • 6
  • 16
  • @Keith...I updated my post my friend...and tried your suggestion. I still can't get it to work :( – AdamH Nov 04 '14 at 16:51
  • Is it because the script is searching the parent page rather than the iframe contents? – AdamH Nov 04 '14 at 16:52
  • That could be why. Check the link to get the iframe contents, and then try the query in the context of those contents. http://stackoverflow.com/questions/1088544/javascript-get-element-from-within-an-iframe – Keith Enlow Nov 04 '14 at 16:54