...

View Full Version : Resolved Reference to Select box value doesn't work in IE



Angie
06-25-2009, 11:05 PM
I have a php page with an html form in it that has a select drop-down box in it. When I try to validate the value, it works in Firefox but not IE7. I narrowed it down to an alert. This shows the correct selected value when I submit the form in Firefox, but is blank in IE7. I am tearing out my hair in frustration here. Can anyone figure this out or suggest alternatives? Thanks in advance.


alert("month: " + frm.BirthDateMonth.options[frm.BirthDateMonth.selectedIndex].value);


I can show more of the code if necessary.

tsclan
06-25-2009, 11:31 PM
It might help if we had the related HTML but does this help at all


alert("month: " + document.forms[0].BirthDateMonth.options[document.forms[0].BirthDateMonth.selectedIndex].value);

Angie
06-26-2009, 12:21 AM
Thanks so much for the reply! Yes, I had tried that (and just did again), but in still does not work in IE. Here is the form code:



<form name="frm" method="post" action="<?php $_SERVER['PHP_SELF'];?>" onSubmit="return valid_form(this);">
.
.
.
<select name="BirthDateMonth">
<?php
if($BirthDateMonth != ""){
?>
<option selected><?=$BirthDateMonth;?></option>
<?php
}
else {
echo"<option>--</option>";
}
?>
<?php
for($i=1; $i <= 12; $i++){
echo"<option>$i</option>";
}
?>
</select>
.
.
.
<input type="submit" value="Next Step" name="submitReg">
</form>


The javascript is in an include file, which is included inside a header include file by the line:

<script language="javascript" src="js/registration.js"></script>

And the js function is:


function valid_form(frm){

message = "";
if(frm.BLName.value == "" || frm.BLName.value == " "){
message = "Please enter your Birth Last Name. ";
frm.BLName.focus();
}
alert("month: " + document.forms[0].BirthDateMonth.options[document.forms[0].BirthDateMonth.selectedIndex].value);
.
.
.
}


The dots indicate other code I haven't shown but is most likely not relative. The thing is it WORKS in Firefox. Why not in IE is what I can't figure out. :-P

tsclan
06-26-2009, 01:35 AM
Ahh I see now you are wanting to return the text rather than the value. In Firefox if the value attribute is not set, text should be returned. So try:


alert("month: " + frm.BirthDateMonth.options[frm.BirthDateMonth.selectedIndex].text);

Angie
06-26-2009, 02:33 AM
No, actually I want to return the value not the text. And, in Firefox it DOES return 3, but in IE it is blank, returning nothing. I did try the text code, just in case, but still FF works and IE is blank. :-(


Ahh I see now you are wanting to return the text rather than the value. In Firefox if the value attribute is not set, text should be returned. So try:


alert("month: " + frm.BirthDateMonth.options[frm.BirthDateMonth.selectedIndex].text);

Angie
06-26-2009, 02:38 AM
OMG, I see what you mean. I totally forgoy the value part ot the option tag element. DOH! But, why did it work in Firefox? And why didn't the text code work? Oh, well, I can fix it all now. Thanks so much for your help! I feel so stupid - me, a web developer/coder for 10 years and I make a stupid mistake like this. :p Oh, well, it happens I guess.

Angie
06-26-2009, 02:40 AM
How do I mark this 'resolved', or can I?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum