0
ajaxRequest.onreadystatechange = function(){
  if(ajaxRequest.readyState == 4){
     var ajaxDisplay = document.getElementById('detail');
     ajaxDisplay.innerHTML = ajaxRequest.responseText;
     }
  }
  var prezime = document.getElementById('form1').getAttribute('value');
  var queryString = "?prezime=" + prezime ;

PHP

echo '<input type="text" id="form1" class="button1" value="'. $row["prezime"] .'" 
name="'. $row["prezime"] .'" onclick="ajaxFunctionII()" >';
echo("</form>");
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
user1024610
  • 37
  • 1
  • 7

4 Answers4

2

Id is always unique to one element, you should not use same id for more than one element. even though you use, the getElementById will select only the 1st element the DOM find, it wont look for any other element.

Make use of name or class and to get these elements use getElementsByName and getElementsByClassName.

Reference

dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58
0

More than one element with same ID is bad, invalid and will cause problems. Don't do that.

Give each element different ID and if you want to have them in "groups" give them a name.

To get collection of elements by name have this:

var arrButtons = document.getElementsByName("detail");
ajaxDisplay = arrButtons[1];
ajaxDisplay.innerHTML = ajaxRequest.responseText;

In the above, you will assign the second button.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

Ideally we should be having only one element within a DOM, with any given id value.

You can try document.getElementsByTagName and document.getElementsByName.

If you are using jQuery, it should be very simple $('#id') or $('.classname') will return all matching elements.

nkm
  • 5,844
  • 2
  • 24
  • 38
0

you should go with class instead of id.the same issue is solved on the given link please check that.

Get multiple elements by Id

Community
  • 1
  • 1
er.miteshp
  • 75
  • 2
  • 11
  • i getting name from mysql search in php, which is call back with ajax to html, how i can call that in html if i don't know name? – user1024610 Feb 02 '12 at 10:24
  • so did you use jquery? if yes then it is easy. you can use $('#idname').each(function(){$(this).val();}) – er.miteshp Feb 02 '12 at 11:08