...

View Full Version : Grabbing select box value doesn't work in IE



grantman
08-20-2007, 11:36 PM
Hi,

I'm trying to take the value selected from a pull-down (<select>) list and have it display in another part of the web page. It works fine in Firefox but not in Internet Explorer (it comes up as the number zero no matter what number you choose). I know there is a known issue in IE with reading values like this, but I cannot figure out how to make this work. Thanks for taking a look.



<script TYPE="text/javascript">
function calculate_answer(form){

//grab value from select box
var theanswer=form.q22.value;

//multiple that by 1.4
theanswer=theanswer*1.4;

//round off to whole number
theanswer=Math.round(theanswer);

//this is the object where answer will be placed
key=document.getElementById("answer_goes_here");

//have that value show up on Q23
key.innerHTML=theanswer;
}
</script>


<form name="myform">

Select the starting number:
<select NAME="q22" ID="q22" ONCHANGE="calculate_answer(document.myform);">
<option VALUE="">--Select--</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select>

The calculated number is <span ID="answer_goes_here">(Answer to Q22 goes here)</span>

</form>

Arty Effem
08-20-2007, 11:47 PM
Hi,

I'm trying to take the value selected from a pull-down (<select>) list and have it display in another part of the web page. It works fine in Firefox but not in Internet Explorer (it comes up as the number zero no matter what number you choose). I know there is a known issue in IE with reading values like this, but I cannot figure out how to make this work. Thanks for taking a look.
It's not an issue, it's a matter of complete HTML. Try assigning values to the options.

grantman
08-20-2007, 11:53 PM
Wow, how did I miss that? Thanks. I wasted several hours on this thinking that IE had a javascript bug that I had to work around when it was just being strict about the form values.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum