Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-25-2009, 10:05 PM   PM User | #1
Angie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
Reference to Select box value doesn't work in IE

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.

Last edited by Angie; 06-26-2009 at 03:36 AM.. Reason: resolved
Angie is offline   Reply With Quote
Old 06-25-2009, 10:31 PM   PM User | #2
tsclan
Regular Coder

 
Join Date: Aug 2003
Location: scotland, edinburgh
Posts: 176
Thanks: 5
Thanked 1 Time in 1 Post
tsclan is an unknown quantity at this point
It might help if we had the related HTML but does this help at all

Code:
alert("month: " + document.forms[0].BirthDateMonth.options[document.forms[0].BirthDateMonth.selectedIndex].value);
tsclan is offline   Reply With Quote
Old 06-25-2009, 11:21 PM   PM User | #3
Angie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
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:

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:
Code:
<script language="javascript" src="js/registration.js"></script>
And the js function is:
Code:
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
Angie is offline   Reply With Quote
Old 06-26-2009, 12:35 AM   PM User | #4
tsclan
Regular Coder

 
Join Date: Aug 2003
Location: scotland, edinburgh
Posts: 176
Thanks: 5
Thanked 1 Time in 1 Post
tsclan is an unknown quantity at this point
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:

Code:
alert("month: " + frm.BirthDateMonth.options[frm.BirthDateMonth.selectedIndex].text);
tsclan is offline   Reply With Quote
Users who have thanked tsclan for this post:
Angie (06-26-2009)
Old 06-26-2009, 01:33 AM   PM User | #5
Angie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
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. :-(

Quote:
Originally Posted by tsclan View Post
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:

Code:
alert("month: " + frm.BirthDateMonth.options[frm.BirthDateMonth.selectedIndex].text);
Angie is offline   Reply With Quote
Old 06-26-2009, 01:38 AM   PM User | #6
Angie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
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. Oh, well, it happens I guess.
Angie is offline   Reply With Quote
Old 06-26-2009, 01:40 AM   PM User | #7
Angie
New to the CF scene

 
Join Date: Jun 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Angie is an unknown quantity at this point
How do I mark this 'resolved', or can I?
Angie is offline   Reply With Quote
Reply

Bookmarks

Tags
ie7, javascript, select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 AM.


Advertisement
Log in to turn off these ads.