473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to use a function to define a hidden input field

I want to specify the value of an input field using the return from a
function. I want to do something this this:

<script>
function value() {
return "the value";
}
</script>

<form>
<input name="theValue" type="hidden", value=value()>
</form>

but it does not work. How do I accomplish this?

Thanks
Jul 23 '05 #1
2 2201
Ron Aronica wrote:
I want to specify the value of an input field using the return from a
function. I want to do something this this:

<script>
function value() {
return "the value";
}
</script>

<form>
<input name="theValue" type="hidden", value=value()>
</form>

but it does not work. How do I accomplish this?

Thanks


Hi,

Just set it like you set any other field:
before i show you how, you should first use good syntax.

1) Name your form, so you can adres it!
2) <input name="theValue" type="hidden", value=value()>
is bad.
It should be:
<input name="theValue" type="hidden", value="someValueHere">

3) better use the following scripttag:
<script type="text/javascript">
Now you can do the following:

I added a button to fire an event which I use to set your value to the
hidden field. Of course I don't know how you will use it, this is just used
to call the function setHiddenValue().
-------------------------------------
<script type="text/javascript">
function value() {
return "the value";
}

function setHiddenValue(){
hiddenvalue=value();
document.forms["myForm"].theValue.value=hiddenvalue;
}

</script>

<form name="myForm">
<input name="theValue" type="hidden" value="">
<input type="button" value="Click me to set hidden value"
onClick="setHiddenValue()">
</form>

-------------------------------------

I coded an extra function to show how things work.
You can also put the whole logic into 1 line.

setting a simple value always works like this:
document.forms["*formname*"].*formelementname*.value=*newvalue*;

Hope that helps you.

Regards,
Erwin Moller
Jul 23 '05 #2
Erwin Moller wrote:
Ron Aronica wrote:

I want to specify the value of an input field using the return from a
function. I want to do something this this:

<script>
function value() {
return "the value";
}
</script>

<form>
<input name="theValue" type="hidden", value=value()>
</form>

but it does not work. How do I accomplish this?

Thanks

Hi,

Just set it like you set any other field:
before i show you how, you should first use good syntax.

1) Name your form, so you can adres it!
2) <input name="theValue" type="hidden", value=value()>
is bad.
It should be:
<input name="theValue" type="hidden", value="someValueHere">

3) better use the following scripttag:
<script type="text/javascript">
Now you can do the following:

I added a button to fire an event which I use to set your value to the
hidden field. Of course I don't know how you will use it, this is just used
to call the function setHiddenValue().
-------------------------------------
<script type="text/javascript">
function value() {
return "the value";
}

function setHiddenValue(){
hiddenvalue=value();
document.forms["myForm"].theValue.value=hiddenvalue;
}

</script>

<form name="myForm">
<input name="theValue" type="hidden" value="">
<input type="button" value="Click me to set hidden value"
onClick="setHiddenValue()">
</form>

-------------------------------------

I coded an extra function to show how things work.
You can also put the whole logic into 1 line.

setting a simple value always works like this:
document.forms["*formname*"].*formelementname*.value=*newvalue*;

Hope that helps you.

Regards,
Erwin Moller


Thanks Erwin, This is what I need to know. I agree with your formatting
comments. I was only trying to show the key items, not the complete code.

Ron
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
by: pablo | last post by:
Dear News Groupers, I'am trying to send a php array with a hidden input field from a form to another script. The array is NOT made directly by way of <input name="arrayname" />. The array is...
1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
4
by: WB | last post by:
Hi, I need to validate a hidden input in my webform to ensure that it's got value. The controls look something like this: <input id="HidSelectedStates" type="hidden" runat="server" /><br...
12
by: effendi | last post by:
I wrote the following function and tested it in MSIE, Firefox and Mac Safari, Works in all but the Safari. What can I do to rectify this? function processBackground(){ for (n=1;n<11;n++) { ...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.