Solved

How do I get values from select list, checkbox and radio button using getElementById?

Posted on 2010-08-22
7
399 Views
Last Modified: 2012-06-27
How do I get values from select list, checkbox and radio button using getElementById?

I want to get values from a filled out form onto a popup specification. The form contains text, textareas, select lists, checkboxes and radio buttons. To get the values from text and textareas, I can use .value in the end in order to get the filled in value of a text field or text area, like this:

document.getElementById("Specadress").innerHTML=window.opener.document.getElementById("adress").value

Is it the same to get the values for select lists, checkboxes and radio buttons?

In the form, do I need to assign a value for each text field, textarea, option in select list, alternative for checkbox, alternative for radio button?
0
Comment
Question by:hermesalpha
  • 4
  • 2
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 105 total points
ID: 33497761
select :
document.getElementById("mySelectID").options[document.getElementById("mySelectID").selectedIndex].value

checkbox:
document.getElementById("myCheckboxID").getAttribute("value")

radio button :
document.getElementById("myRadioID").getAttribute("value")

0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 105 total points
ID: 33497768
textarea :
document.getElementById("myTextareaID").value
0
 

Author Comment

by:hermesalpha
ID: 33497883
Is this part correct for the select list?:

options[document.getElementById("mySelectID").selectedIndex].value
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 105 total points
ID: 33497887
no :
document.getElementById("mySelectID").options[document.getElementById("mySelectID").selectedIndex].value

look better like this :

var sb = document.getElementById("mySelectID");
sb.options[sb.selectedIndex].value;
0
 
LVL 29

Assisted Solution

by:Badotz
Badotz earned 20 total points
ID: 33497898
And don't forget:

var sb = document.getElementById("mySelectID");
sb.options[sb.selectedIndex].text; ' The displayed portion of the OPTION
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33614466
Thanks for the points!
0
 
LVL 29

Expert Comment

by:Badotz
ID: 33617737
No worries - glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now