tags:

views:

21

answers:

1

Hi all,

Recently, I came across a web page where someone asked how to add some value to a hidden field.
Since I am new to JQuery, I tried using Javascript instead and came up with this code:

<html>
<head>
<script type="text/javascript">
<!--
function t() {
document.testform.testfield.value = "helloworld";
}
-->
</script>
</HEAD>
<body onLoad="t()">
<form name="testform" id="testform">
<input type="hidden" name="testfield" id="testfield">
</form>
</body>
</html> 

The code works only in non-hidden Text Box field.
I am not sure if JQuery can do it.
Is it possible to add a value to a hidden text box field in JQuery?

Please help if you could.

+4  A: 

yes ;)

$("input[name=testfield]").attr("value","helloworld");

or

$("#testfield").attr("value","helloworld");

or

$("#testfield").val("helloworld"); //Thx Felix Klinger

and if you wan't to show the form:

$("input[name=testfield]").attr("type","text");

or

$("#testfield").attr("type","text");
CuSS
Or just `$("#testfield").val("helloworld");` Btw., `testform` is wrong, should be `testfield` and I don't think that you can make a input field of type `hidden` visible with `show`.
Felix Kling
@Felix Kling - Thanks ;) i need to sleep a little ahaha
CuSS
Thanks Felix for the correction.