开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜