Quote:
Originally Posted by John Benson
Ok I'm new to OOP and it makes sense that an ID should be unique but if I were to change ID to class could I use the above code to update the elements that have a class of citystate? or Is there another structure that I should use like span? and How would I need to change the above code?
|
if you use only div which you want to fill with data you don't need to add a class attribute for this pourpuse. You can use getElementsByTagName.
a sketch, not sure about syntax:
Code:
// get the form using a id, as in your code
var myform = document.getElementById(formid);
// get a array of all divs inside myform
var divarray = myform.getElementsByTagName('div');
// fill the divs
for(i=0; i< divarray.length;i++){
divarray[i].innerHTML = yourdata;
}
probably a better method if you use responseText is to build the divs in php and insert/append the response inside the form.
Code:
// get the form using a id, as in your code
var myform = document.getElementById(formid);
// insert all divs inside myform
myform.innerHTML = ajax.responseText + additional_fixed_code;
here additional_fixed_code is code for submit button, other controls, and so on.
take care to have valid (x)html else will be a pain to find why didn't work( remove last < /body> from your page).
Edit: first time you insert this could work:
Code:
var additional_fixed_code = myform.innerHTML;
myform.innerHTML = ajax.responseText + additional_fixed_code;
second time you must get rid of divs
best regards