简体   繁体   中英

Get value of hidden input field in JS

I need to get the value of a hidden input field using JS,

   var credoff = parseInt($(this).children('input.credoff:hidden').val());

which works fine in FF but does not work in IE, the input im talking of is the following...

<input type='hidden' value='$row->coff' class='credoff' name='credoff'/> 

Could you try input[type='hidden'] ?

Are there many other elements with the 'credoff' class?

There are comments in the jQuery documentation for the:hidden selector related to this.

http://api.jquery.com/hidden-selector/

Apparently in IE, the:hidden selector also selects elements, so it's possible that you're not getting back the right element. You could try

var credoff = parseInt($(this).children('input.credoff:hidden').not('option').val());

This might work:

var credoff = parseInt($(this).children('input[name="credoff"]').val());

Although I don't know what 'this' is. More code would be helpful.

Or this:

var credoff = parseInt($(':input[type:"hidden"][name:"credoff"]').val());

This must work:

var credoff = parseInt($(this).children('input[name="credoff"][type="hidden"]').val());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM