469,345 Members | 6,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,345 developers. It's quick & easy.

How to retrieve "option value" info from select tag

8
Hi guys!
How I can retrieve "option value" info from select tag?
I am using this code, but it is only let me get "name".
I need to pass this value to second select tag.
I found this code here:
http://adamv.com/dev/javascript/http_request
but they do not have any instructions how to retrieve option values.

----------JS------------

[HTML]<script>
function handleOnChange(dd1)
{
var idx = dd1.selectedIndex;
var val = dd1[idx].text;
var par = document.forms["frmSelect"];
var parelmts = par.elements;
var prezsel = parelmts["prez"];
var course = val;
if (course != "-Select a Course-")
{
Http.get({
url: "./" + course + ".txt",
callback: fillPrez,
cache: Http.Cache.Get
}, [prezsel]);
}
}

function fillPrez(xmlreply, prezelmt)
{
if (xmlreply.status == Http.Status.OK)
{
var prezresponse = xmlreply.responseText;
var prezar = prezresponse.split("|");
prezelmt.length = 1;
prezelmt.length = prezar.length;
for (o=1; o < prezar.length; o++)
{
prezelmt[o].text = prezar[o];
}
}
else
{
alert("Cannot handle the AJAX call.");
}
}
</script>[/HTML]

------HTML----------

[HTML]<form name="courseSelect">

<select name="course" onChange.value="handleOnChange(this);">

<option value='0'>-Select a Course-</option>
<option value='1'>Course Name 1</option>
<option value='2'>Course Name 2</option>
<option value='3'>Course Name 3</option>

</select>

</form>
[/HTML]

Thank you

Sergey.
Aug 5 '08 #1
6 6932
hi..
1. you have to first change onchange.value TO only onchange.
2. U can get the value of th select field easily by using document.getElementById.value....
Aug 6 '08 #2
cepera
8
Thank you samikhan83.
I am newbyte in JS & AJAX
Can you please post some example?
Aug 6 '08 #3
RamananKalirajan
607 512MB
Hi Dude, hope this code may help you. If u have any doubts post it I will surely help u out.

[HTML]<html>
<head>
<script language="javascript">
function doThis()
{
var sel = document.getElementById('mySelect1').selectedIndex ;
var selObj = document.getElementById('mySelect1').options[sel].text;
document.getElementById('mySelect2').add(new Option(selObj,selObj));
document.getElementById('mySelect1').remove(sel);

}
</script>
</head>
<table>
<tr>
<td>
<select id="mySelect1" size="10" onclick="doThis()">
<option>Apple</option>
<option>Orange</option>
<option>Mango</option>
<option>Grape</option>
<option>Pine</option>
</select>
</td>
<td>
<select id="mySelect2"size="10" >
</select>
</td>
</tr>
</table>
</html>[/HTML]

Regards
Ramanan Kalirajan
Aug 6 '08 #4
acoder
16,027 Expert Mod 8TB
Change line 5 to:
Expand|Select|Wrap|Line Numbers
  1. var val = dd1[idx].value;
or replace lines 4 and 5 with:
Expand|Select|Wrap|Line Numbers
  1. var val = dd1.value;
Aug 6 '08 #5
cepera
8
Change line 5 to:
Expand|Select|Wrap|Line Numbers
  1. var val = dd1[idx].value;
or replace lines 4 and 5 with:
Expand|Select|Wrap|Line Numbers
  1. var val = dd1.value;

!!! THANK YOU VERY MUCH ACODER !!!
Aug 6 '08 #6
acoder
16,027 Expert Mod 8TB
You're welcome :) Post again if you have more questions.
Aug 6 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Neil H | last post: by
4 posts views Thread by millw0rm | last post: by
4 posts views Thread by rebeccatre | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.