vozzek Posted January 6, 2008 Share Posted January 6, 2008 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! Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted January 6, 2008 Share Posted January 6, 2008 The code looks fine, I can't see anything wrong with it. There are some differences between firefox and ie but I use similar code to you in both and it works for me. So I'm not sure it could be something minor. Quote Link to comment Share on other sites More sharing options...
SirChick Posted January 7, 2008 Share Posted January 7, 2008 I don't know a great deal but perhaps JS is on different settings in IE to FF or something :S Wild guess Quote Link to comment Share on other sites More sharing options...
vozzek Posted January 7, 2008 Author Share Posted January 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.