Jump to content

[SOLVED] Works in Firefox... not in I.E. Why?


vozzek

Recommended Posts

This is frustrating.  I've got a pretty straightforward script that forces a user to select an option from the dropdown box OTHER than the defaulted "Please Select" option.  It works fine in Firefox, but I.E. allows you to add the item to the shopping cart with 'Please Select' as the option.  Grrrr....

 

<script type="text/javascript">
<!--
function validateAddToCart() {
  var valid = 1;
  var errmsg = "";
  var jopta = document.getElementById('option_a');
  if (jopta) {
     if (jopta.value == "Please Select") {
    errmsg = "Please make sure all drop-down selections are made.";
            valid = 0;
    }
     }
  if (valid == 0)
        {
        alert(errmsg);
        return false;
        } else {
	    return true;
	}
}
//-->
</script>

 

Anyone see an obvious problem here, or am I missing something?  I'm also open to better ways to do this.  Thanks!

 

Link to comment
Share on other sites

I found out the answer, so I'm posting it here for everyone who's interested.  Maybe I can help someone else out, after all the help you guys have given me.  :)

 

IE (at least IE6 and below) doesn't treat options in a select as normal element nodes. You can't reference them by id, but need to use the indexes of the select element's options.  So in the example having to do with my website, I only cares about the first index...  so I just test that the select's selectedIndex is not 0.

 

Works great.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.