/    Sign up×
Community /Pin to ProfileBookmark

Get child of select element

I want to look through the document and find all the <select> elements and then for each one of those return the value of the option that has been selected with each one of those selects.

Here is what I have so far:

[code=html]<html>
<head>
<title></title>
</head>
<body>
<div id=”abbr_markup_div”>

I am going to visit the <select name=”selectFormAbbr”><option value=”US”>US</option><option value='<abbr title=”United States”>US</abbr>’>United States</option></select>, with all the rest of us in a big party of <select name=”selectFormAbbr”><option value=”DSc”>DSc</option><option value='<abbr title=”Doctor of Science”>DSc</abbr>’>Doctor of Science</option></select> holders. The US can also be written as <select name=”selectFormAbbr”><option value=”USA”>USA</option><option value='<abbr title=”United States of America”>USA</abbr>’>United States of America</option></select> or U.S.A, in case you are interested in that uninteresting fact.

Then I will write some <abbr title=”css”><select name=”selectFormAbbr”><option value=”CSS”>CSS</option><option value='<abbr title=”Cascading Style Sheets”>CSS</abbr>’>Cascading Style Sheets</option></select></abbr> stylesh<select name=”selectFormAbbr”><option value=”ee”>ee</option><option value='<abbr title=”er enghraifft”>ee</abbr>’>er enghraifft</option></select>ts, and write some crappy non-<select name=”selectFormAbbr”><option value=”W3C”>W3C</option><option value='<abbr title=”World Wide Web Consortium”>W3C</abbr>’>World Wide Web Consortium</option></select> compliant <select name=”selectFormAbbr”><option value=”HTML”>HTML</option><option value='<abbr title=”HyperText Markup Language”>HTML</abbr>’>HyperText Markup Language</option></select>.
<select name=”selectFormAbbr”><option value=”NASA”>NASA</option><option value='<abbr title=”National Aeronautics and Space Administration”>NASA</abbr>’>National Aeronautics and Space Administration</option></select> <select name=”selectFormAbbr”><option value=”UK”>UK</option><option value='<abbr title=”United Kingdom”>UK</abbr>’>United Kingdom</option></select> <select name=”selectFormAbbr”><option value=”IS”>IS</option><option value='<abbr title=”Information Services”>IS</abbr>’>Information Services</option></select> <select name=”selectFormAbbr”><option value=”PCA”>PCA</option><option value='<abbr title=”Prifysgol Cymru, Aberystwyth”>PCA</abbr>’>Prifysgol Cymru, Aberystwyth</option></select> <select name=”selectFormAbbr”><option value=”AM”>AM</option><option value='<abbr title=”Ante Meridium”>AM</abbr>’>Ante Meridium</option></select> <select name=”selectFormAbbr”><option value=”PM”>PM</option><option value='<abbr title=”Post Meridium”>PM</abbr>’>Post Meridium</option></select>, Then I will ring the <select name=”selectFormAbbr”><option value=”CQFW”>CQFW</option><option value='<abbr title=”Credit and Qualifications Framework for Wales”>CQFW</abbr>’>Credit and Qualifications Framework for Wales</option></select>, for no particular reason. Eg, just for the <b>great</b> fun that it is.

</div>

<button onclick=”change_abbr()”>Change</button>

<script type=”text/javascript”>

function change_abbr()
{
abbrDiv = document.getElementById(“abbr_markup_div”);
items = abbrDiv.getElementsByTagName(“select”);

for(i=0;i<items.length;i++)
{

}

}

</script>
</body>
</html>
[/code]

So for each of those selects I want to return the value of the option that is selected. Any help please?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@slaughtersFeb 27.2009 — Just try items[i].value



The current value of a select is what ever option was just selected.
Copy linkTweet thisAlerts:
@happyeddieauthorFeb 27.2009 — Thank you ?

Is it possible to remove that node and replace it with currentValue, is the replace() fucntion the correct way to go?

[code=html]
function change_abbr()
{
abbrDiv = document.getElementById("abbr_markup_div");
items = abbrDiv.getElementsByTagName("select");

for(i=0;i<items.length;i++)
{
var currentValue = items[i].value;

items = items.replace(items, currentValue);//wrong
}


}
[/code]
×

Success!

Help @happyeddie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...