Page 1 of 1

How to do the multiple items with the same id?

Posted: Sat Mar 01, 2008 1:19 pm
by kiko
Hi all,
I'm having the problem while using the edit-in-place scripts (http://24ways.org/2005/edit-in-place-with-ajax) from internet. It's ok when i just used for one text id, but after i added a while loop because of multiple items and it become only the 1st text id content works. So below here i post a piece of my code, hope any here can help on this. How to do the multiple items with the same id? Please help. Thank you very much.

Code: Select all

 
while($disp=mysql_fetch_array($disp_de))
{           
echo '<tr><td>';
$dis= $disp['pp_desc'];
echo "<p id=\"desc\">".$dis."</p>";
echo '</td></tr>';
}
 

Re: How to do the multiple items with the same id?

Posted: Sat Mar 01, 2008 1:53 pm
by Jonah Bron
IDs are meant to be a one-time occurance.

Re: How to do the multiple items with the same id?

Posted: Sun Mar 02, 2008 4:54 am
by kiko
hi PHPyoungster,
thanks,
PHPyoungster wrote:IDs are meant to be a one-time occurance.
then how to make it able to occur for everytime in the while loop? Can it be done? this is because i had tried the code that inside the comments of the page above it changed the scripts inside function init(), and it didn't work for my case.

Re: How to do the multiple items with the same id?

Posted: Sun Mar 02, 2008 5:01 am
by Chris Corbyn
I don't really understand what it is you're trying to do, but just make the IDs different so they are unique.

Code: Select all

$i = 0;
while($disp=mysql_fetch_array($disp_de))
{          
  echo '<tr><td>';
  $dis= $disp['pp_desc'];
  echo "<p id=\"desc_$i\">".$dis."</p>";
  echo '</td></tr>';
}

Re: How to do the multiple items with the same id?

Posted: Sun Mar 02, 2008 9:51 am
by kiko
hi Chris Corbyn,
thanks for help. But it can't work. Should I modify anything inside the js file?
here is i tried to modify the function inside the editinplace.js, which i refer to the comments that below the page as i stated before in this post. But it can't work to me also.

Code: Select all

function init(){
 
var max = 50;
 
for (i = 1; i < max; i++){
 
makeEditable(‘item_’+i);}
 
}
Any expert please guide, thanks. :?

Re: How to do the multiple items with the same id?

Posted: Sun Mar 02, 2008 9:01 pm
by kiko
Anyone? :(

Re: How to do the multiple items with the same id?

Posted: Mon Mar 03, 2008 9:46 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.

Re: How to do the multiple items with the same id?

Posted: Wed Mar 05, 2008 5:13 am
by kiko
Hi, does any know how to slove this problem? :? Thanks.

Re: How to do the multiple items with the same id?

Posted: Wed Mar 05, 2008 8:09 am
by Zoxive
kiko wrote:Hi, does any know how to slove this problem? :? Thanks.
As everyone else has already stated, it is not possible to "target" multiple items with the same ID. The dom only will recognize one, this is the whole purpose of IDS, to be unique.

Classes are made to not be unique. Have a look at them, if you are using a JavaScript framework it is pretty simple to select all of the same classes.

Code: Select all

${'.classname')

Re: How to do the multiple items with the same id?

Posted: Wed Mar 05, 2008 11:00 am
by kiko
thanks, Zoxive. Actually I had just solved this problem but now it will appear the error on page icon at the bottom left of my page. You know about this Zoxive? I modified as the below code. Thank you.

Code: Select all

 
 while($disp=mysql_fetch_array($disp_de))
{
    echo '<tr><td>';
    $dis= $disp['pp_photo_desc'];
[b]    echo '<p id="desc'.$a.'">'.$dis."</p>";[/b]
    echo '</td></tr>';
    $a++;
}
 
and in the function init()

Code: Select all

 
function init(){
var max=50;
for(i=0; i<max ;i++){
[b]makeEditable('desc'+i);[/b]      //if I put semicolon in the end of i, then I'll not get the error but I'll not get what I need.
}
}