473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2208
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="someValu eHere">

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=val ue();
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="setHid denValue()">
</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* "].*formelementna me*.value=*newv alue*;

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="someValu eHere">

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=val ue();
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="setHid denValue()">
</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* "].*formelementna me*.value=*newv alue*;

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
4944
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or...
4
25549
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 made by normal php code and then submitted between form-tags as echo "<input type='hidden' name=\"arrayname\" value=\"$arrayname\" />" ;
1
9573
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 same name "junk_array". My first field of junk_array is a input type=hidden. All the others fields in junk_array that follow are type=text. I can...
1
1964
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 element. BUT, I don't want that value to be in the actual HTML form, I want it to be created in my submit function. For instance:
6
2734
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 work. Nota() - opens new window. fechaNota() - closes the window opened by Nota() here is the code.
4
11698
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 /><br /> <asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click" Text="Submit" ValidationGroup="submitStates" />...
12
2056
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++) { cellrow="r"+n for (i=1;i<17;i++){ cell=cellrow+"w"+i cellName=cell+"_ID"
1
7484
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 fine the first time (when the input-field is created in a non-dynamical way). The next input-field is created dynamically by a function that is called...
1
7069
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 action="http://cm1web1/WebSurveyComponents/script/ processform.asp" method="post">
0
7896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.