Changing a hidden field

S

sheldonlg

I have what is probably a very simple question, but I am VERY new to
javascript. Here is what I want to accomplish.

I have a text box called zp. I also have a hidden field called frm.
There is also a submit button.

When the submit button is pressed, I want to set the value of the
hidden field, frm, depending upon whether or not there the text field,
zp, is empty. For example, if it is empty I want the hidden field to
be frm="empty" and if there is something there I want it to be
frm="set".

These fields are in inside a form of method "GET" with an action of a
URL. The hidden fields are passed to the new page automatically as
properties at the end of the URL string with the ? and the &. The
action taken in the new page depends upon the value of frm that is
passed.

Would I add an onclick to the submit button or an onexit to the text
box, zp? How to I name the variable? Is it document.frm?

As I said, I am a real beginner here.

Shelly
 
B

brk

Hi Shelly,
Here is the code

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function onSub()
{
if(document.forms[0].zp != null && document.forms[0].zp.value != '')
document.forms[0].frm.value = "set"
else
document.forms[0].frm.value = "empty"
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM METHOD=GET ACTION="" onsubmit="return onSub()">
<INPUT TYPE="text" NAME="zp">
<INPUT TYPE="hidden" name="frm">
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>
 
S

sheldonlg

Thank you very much. While waiting for this answer, it dawned on me to
go a location that does this and to look at THAT javascript via view
source. I adapted that script and it works. It is issentially what
you wrote here. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top