Solved

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

Posted on 2010-08-22
7
402 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 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