开发者

IE error with parseInt dropdown value (jquery val())

开发者 https://www.devze.com 2022-12-11 17:24 出处:网络
I have an dropdown with the following in it: <select id=\"shipping\" name=\"shipping_option\"> <option SELECTED value=\"60\">R60</option>

I have an dropdown with the following in it:

<select id="shipping" name="shipping_option">
<option SELECTED value="60">R60</option>
<option value="90">R90</option>     
<option value="100">R100</option>                           
</select>

Then, when the content of the dropdown is changed, javascript runs updateTotal(), which is the following:

function updateTotal() {
            total = parseInt($("#shipping").val());
        }

Now that works fine in Firefox and Safari, but not in IE. It just doesn't work. It says ob开发者_开发百科ject doesn't support function.

Is this a bug in IE, or a bug in jQuery relating to IE? As I said, this works perfectly, just not in IE.


Some possible problems -- are you sure the <select> with the id shipping has loaded and has not been removed from the DOM? Is there another element with the id shipping? Is the value really a number? Also, the total variable, are you certain it was initialized with var to make it accessible where you're using it?

One note, it's a good idea to use parseInt() with the second parameter, so parseInt(foo, 10); to make sure it's parsed as a decimal number.

Try checking your code in jslint to see what other errors may be causing problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号