473,512 Members | 15,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cant get getElementById() to work

2 New Member
i am trying to create a form like this

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5.  
  6. function setValue(id,set)
  7. {
  8. document.myform.getElementById(id).value = set;
  9. }
  10.  
  11.  
  12. </script>
  13. </head>
  14. <body>
  15. <form name="myform" action="button_submit.php" method="post"> 
  16.  
  17. <input type="button" onclick="setValue('qu1','1')" value="set to 1" />
  18. <input type="button" onclick="setValue('qu1','2')" value="set to 2" />
  19. <input type="button" onclick="setValue('qu1','3')" value="set to 3" />
  20. <input type="button" onclick="setValue('qu1','4')" value="set to 4" />
  21. <input type="button" onclick="setValue('qu1','5')" value="set to 5" />
  22. <input type="button" onclick="setValue('qu1','6')" value="set to 6" />
  23.  
  24. <input type="hidden" id="qu1" name="q1" value="0" />
  25.  
  26. <input type="submit" value="submit" />
  27.  
  28.  
  29. </form>
  30.  
  31. </body>
  32. </html>
though it doesnt work for me. if i replace the getElementById() with the name of the element i will work but that is not what i want because i want one function to do the duplicates of this form.

any help would be greatly appreciated.
Jul 14 '09 #1
2 1768
gits
5,390 Recognized Expert Moderator Expert
try:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById(id).value = set
  2.  
since getElementById() is a method of the document-object.

kind regards
Jul 15 '09 #2
benshep
2 New Member
thanks, that cleared up the problem. I had done the same thing before but its nice to know why.

cheers
Jul 15 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2685
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
3868
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
5442
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
3
9241
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
21
7908
by: vadymus | last post by:
Hello, I need to compare 2 id names but not their values. For example: document.getElementById(i) == document.getElementById(j) these elements above seem to give error or do not work. My...
4
1790
by: Beemer Biker | last post by:
I am adding at bindtime an htmlbutton and an html dropdownlist. The idea is to select the item in the list, hit the button and my callback code uses the ID.selectedindex to act on the item that...
3
9645
by: edai | last post by:
I am working on a code where I am loading XML data from a file on the server using ....... if (xmlhttp.readyState==4) { value=xmlhttp.responseText; var parser=new DOMParser();...
7
2300
by: griffinheart | last post by:
hey there this script works fine in firefox. but in ie the this call document.getElementById(form).style.display='block'; gives me object required, well i don't know much about java and can't...
5
5753
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.