views:

68

answers:

1

Hi. I have this:

    while( $rowData = @mysql_fetch_assoc($selectRows2) )
    {
?>
<div id="stemmeto"><a href="#" id="thelink" onclick="window.parent.OpenVote(<? echo $_GET['id']; ?>, '<? echo $rowData['username']; ?>');">
<?php echo $rowData['username']; ?> </a></div>

<div id="stemme">
<a href="#" id="thelink" onclick="window.parent.OpenVote(<? echo $_GET['id']; ?>, '<? echo $rowData['username']; ?>');">
<? echo $rowData['stemme']; ?></div></a><br />
<?
    }

Now this should activate OpenVote function with (id, username) in the parent.window.. But for some reason this only works for first column, that comes out, nothing is happening when i click the others.. I have tried to remove that column, to check to see if its specially just that column, but it wasnt, its always the "first" column that echo´s out in the while(), that i can click on.. what should i do?

Here's the OpenVote script on the parent window(index.php)

function OpenVote(id, stemme)  {
  var postThisShit = 'battles/infoaboutvote.php?id='+id+'&stemme='+stemme;
  $.post(postThisShit, function(data){
        $(".showinfo").html(data).find(".getinfo").fadeIn("slow")
  });
  }

And the #thedialog on index.php:

<div id="thedialog" title="Showing..">
    <p class="showinfo">
        You shouldn't see this, something went wrong..
    </p>
</div> 
+2  A: 

The id attribute must be unique across your entire document. Your loop is creating multiple elements with the same id, which will cause behavior like you're describing when trying to interact with the elements. Try appending a unique value to the end of the id, such as id-1, id-2, id-3, etc.

Jimmy Cuadra
Hi, are you talking about the <div id? or where? and how should i do like you say?
Karem
These three IDs are currently exactly the same for each iteration of the loop: `stemmeto`, `thelink`, and `stemme`. One way to make them unique is to use a counter variable to keep track of the loop iteration and append that number to the IDs each time, e.g., in pseduocode: `<? $counter = 0; ?> /* start loop */ <div id="stemme-<? echo $counter; ?>">...</div> <? $counter++; ?> /* end loop */`
Jimmy Cuadra
Any id. Whenever you have <element id="element_id">, no other element can share that id. So like jimmy says, since your loop repeats the id="stemmeto", id="stemme" and id="thelink" over and over, for each item in $rowData, your javascript only works on the first id it encounters with that name.if $rowData is returning a database record, try appending the record id to your ids:<div id="stemmeto_<?php echo $rowData['id'] ?>"><a href="#" id="thelink_<?php echo $rowData['id'] ?>" ...
daybreaker
But if you do like that with "thelink" then my other function: $('#thelink').click(function(){ window.parent.$('div#thedialog').dialog('open'); wont work
Karem
So change `thelink` from an ID to a class.
Jimmy Cuadra
like this:$('.thelink').click(function(){ window.parent.$('div#thedialog').dialog('open'); ?
Karem