Can you have more than one id inside document.getElementById(), like document.getElementById(id1,id2) etc?
Can you have more than one id inside document.getElementById(), like document.getElementById(id1,id2) etc?
No. The method only returns one element reference. This is indicated, in part[1], because of the singular usage of 'element'.Originally Posted by gusblake
Mike
[1] The other, more telling indication is that function specification only lists one argument.![]()
With a little additional code you can grab more than one element, using getElementById(). But, what that additional code is depends upon what elements you want to grab and what you want to do with them. Here is one method:
Code:els=['id1','id2','id3'] for (var i_tem = 0; i_tem < els.length; i_tem++) document.getElementById(els[i_tem]).style.visibility='visible'
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Hey guys, I am trying to dynamiccaly edit a text box depending upon what other fields have been entered.
Sadly I cant post the entire code or a link due to it being an admin script but this is the JS code
Code:function generateproddeschtml(){ <!-- ok generate the product description and place it into the description field --> var NUMBEROF = document.getElementById('numberofrows').value; THEFIELDS = Array(); for (var i = 0; i < NUMBEROF; i++){ THEFIELDS[i] = 'rowtitle_'+i; alert(i); } var HTML = '<table width="460" cellpadding="0" cellspacing="0">'; for (var i_temp = 0; i_temp < THEFIELDS.length; i_teno++){ HTML = HTML + '<tr><td width="17"><img src="http://www.discsexpress.com/img/doughnut_red.gif" width="15" height="15" /></td><td height="21" width="200">'+document.getElementById(THEFIELDS[i_temp]).value+'</td><td width="250">'+document.getElementById('rowdesc_'+i)+'</td></tr>'; } HTML = HTML + '</table>' document.getElementById("description").value = HTML; }any ideas?Code:and the error I get is Error: document.getElementById(THEFIELDS[i_temp]) has no properties Line: 84![]()
There is so much messed up about that code that I cannot be certain of its actual intent. This could be what you want but, it depends upon the HTML of the page it is used on, so I have no idea if that fits. Also, unless the various fields exist and are filled out as expected, there will be problems even if everything else is set up correctly:
If document.getElementById("description") is a text field or text area, that last line should remain as it was:Code:function generateproddeschtml(){ //ok generate the product description and place it into the description field var NUMBEROF = document.getElementById('numberofrows').value*1; var HTML = '<table width="460" cellpadding="0" cellspacing="0">'; for (var i_temp = 0; i_temp < NUMBEROF; i_temp++){ HTML = HTML + '<tr><td width="17"><img src="http://www.discsexpress.com/img/doughnut_red.gif" width="15" height="15" /></td><td height="21" width="200">'+document.getElementById("rowtitle_"+i_temp).value+'</td><td width="250">'+document.getElementById("rowdesc_"+i).value+'</td></tr>'; } HTML = HTML + '</table>' document.getElementById("description").innerHTML = HTML; }
Code:document.getElementById("description").value = HTML;
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Hi there John,Originally Posted by jscheuer1
That looks a lot like my first code I added the array in due to the problem to see if that would cure it, i'll try the code in a few mins and see what happens
Still getting the exact same error
Then, most likely, the number entered in the:
document.getElementById('numberofrows')
field does not agree with the number of:
document.getElementById("rowtitle_"+i_temp)
fields and/or the number of:
document.getElementById("rowdesc_"+i)
fileds.
Also, it would be impossible to get the same exact error, as the new code no longer references:
document.getElementById(THEFIELDS[i_temp])
There could be other problems because, as I mentioned before, without seeing the HTML of the page in question, I cannot know if this code fits with it or visa versa. You should create a demo page that contains all the elements relevant to this portion of code that you are trying to run and either post a link to it or include it as an attachment.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Originally Posted by jscheuer1
I just got a bad felling.... the rows start from 1 not 0 and the for loop starts at 0 which could be causing the error.... bah not enough time to many things ahhh thanks for the help john will have to squeeze it in
Hey gusblake did you try the prototype $() function?? Well if you haven't then here's the link:
http://www.dustindiaz.com/top-ten-javascript/
Scroll down to the last function.
Why should anyone want to use anything from a library as badly-written as Prototype? Moreover, why are you addressing a post six months old?Originally Posted by shachi
People unfamiliar with scripting would do well to avoid it. The rest would do better to write their own code.
Mike
Bookmarks