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

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?
LVL 1
hermesalphaAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
select :
document.getElementById("mySelectID").options[document.getElementById("mySelectID").selectedIndex].value

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

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

0
 
leakim971Connect With a Mentor PluritechnicianCommented:
textarea :
document.getElementById("myTextareaID").value
0
 
hermesalphaAuthor Commented:
Is this part correct for the select list?:

options[document.getElementById("mySelectID").selectedIndex].value
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
leakim971Connect With a Mentor PluritechnicianCommented:
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
 
BadotzConnect With a Mentor Commented:
And don't forget:

var sb = document.getElementById("mySelectID");
sb.options[sb.selectedIndex].text; ' The displayed portion of the OPTION
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0
 
BadotzCommented:
No worries - glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.