By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

Works in Firefox... not in I.E. Why?

P: 40
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....

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. function validateAddToCart() {
  4.   var valid = 1;
  5.   var errmsg = "";
  6.   var jopta = document.getElementById('option_a');
  7.   if (jopta) {
  8.      if (jopta.value == "Please Select") {
  9.         errmsg = "Please make sure all drop-down selections are made.";
  10.             valid = 0;
  11.         }
  12.      }
  13.   if (valid == 0)
  14.         {
  15.             alert(errmsg);
  16.             return false;
  17.         } else {
  18.             return true;
  19.         }
  20. }
  21. //-->
  22. </script>
Anyone see an obvious problem here, or am I missing something? I'm also open to better ways to do this. Thanks!
Jan 6 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 428
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.

Your case only cares about the first, so just test that the select's selectedIndex is not 0.
Jan 6 '08 #2

P: 40
Wow, Mr.hoo, thanks!
Jan 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.