Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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 04:36 AM. Reason: resolved

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post
    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);

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 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);

  • Users who have thanked tsclan for this post:

    Angie (06-26-2009)

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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);

  • #6
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    How do I mark this 'resolved', or can I?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •