473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 7109
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
608 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

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

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
1
by: ouioui | last post by:
Hi, I try to have a communicatition between 2 windows In the first one i have a HTML styled select like that : <form name='addform' id='addform' action='add_dossier.php' method='post' >...
3
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
1
by: Neil H | last post by:
Hi All I am doing a multiple table and field database search, and my problem lies in the options that a user has. In each field, the user can specify a specific value or any value. I take each...
2
by: gabon | last post by:
I'm creating a select entirely through JavaScript and very strangely IE doesn't show the text in the option elements. Here part of the code: this.form_country=document.createElement("select");...
6
by: Mark | last post by:
I first read about this in mvps.org, but the code he gives doesn't seem to work for my form. I"ll post my code below. I'd love it if someone could point out the error in my code. BTW, this is my...
4
by: millw0rm | last post by:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox 1.5??? var anOption = document.createElement("OPTION"); document.getElementById("category").options.add(anOption);...
4
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect">...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.