开发者

Get value from hidden field using jQuery

I have a <inpu开发者_Go百科t type="hidden" value="" id='h_v' class='h_v'> Using jQuery I want to alert the user to this value .

I am using

var hv = $('#h_v).text();
alert('x');

But its not working, any clues!


Use val() instead of text()

var hv = $('#h_v').val();
alert(hv);

You had these problems:

  • Single quotes was not closed
  • You were using text() for an input field
  • You were echoing x rather than variable hv


If you don't want to assign identifier to the hidden field; you can use name or class with selector like:

$('input[name=hiddenfieldname]').val();

or with assigned class:

$('input.hiddenfieldclass').val();


This should work:

var hv = $('#h_v').val();
alert(hv);


html

<input type="hidden" value="hidden value" id='h_v' class='h_v'>

js

var hv = $('#h_v').attr("value");
alert(hv);

example


var hiddenFieldID = "input[id$=" + hiddenField + "]";
var requiredVal= $(hiddenFieldID).val();


var x = $('#h_v').val();
alert(x);


Closing the quotes in var hv = $('#h_v).text(); would help I guess

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜