Liam
Liam

Reputation: 9855

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'/> 

Upvotes: 0

Views: 1014

Answers (5)

sandino
sandino

Reputation: 3842

This must work:

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

Upvotes: 0

redbmk
redbmk

Reputation: 4796

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());

Upvotes: 1

dimi
dimi

Reputation: 1546

Or this:

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

Upvotes: 0

Ryan Doherty
Ryan Doherty

Reputation: 38740

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.

Upvotes: 0

AndyL
AndyL

Reputation: 1655

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

Upvotes: 3

Related Questions