?
Solved

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

Posted on 2010-08-22
7
Medium Priority
?
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 420 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 420 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 420 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 80 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

762 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