Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with undefined values 1

Status
Not open for further replies.

doorbreaker

Programmer
Nov 19, 2002
91
GB
Hi,

I have a hidden field:

<input type="hidden" name="xFirstName" value = "">

I also have a text field called FirstName. I want to set xFirstName to the value of FirstName if xFirstName is empty.

Is it possible to do this?

I tried this:

function tester()
{
document.form.xFirstName = document.form.FirstName.value;
}

I have put some text in the FirstName field. When I submit the form the value of xFirstName comes up as undefined.

On submitting I do the following:

...form action="whatever.asp" onsubmit="return tester();"....

Is this possible? Any ideas?

Many thanks in advance for any help

Chris Moore

 
And name of your form is... ?

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.
 
There is just one form called form - thanks for your advice I will try this out and let you know.

 
Hi,

I've tried using the above solution:

document.forms[0].xFirstName.value = document.forms[0].FirstName.value;

but xFirstName is still undefined on the page I submit to.

If I write the following:

document.forms[0].xFirstName.value = 'James'; then there is no problem and the value comes through as James.

???

Are you sure that this is possible? To clarify, I am filling in the text field 'FirstName' and then on submittal I want to set the value I put in FirstName to also be xFirstName (a hidden field)....

Thanks in advance

Chris
 

This should work:

Code:
document.forms[0].xFirstName.value = document.forms[0].FirstName.value;

If, as you say, it is not working, you will need to post your form code (or better still your full code, or a URL to it), as something strange would appear to be happening.

Dan


The answers you get are only as good as the information you give!

 

Also, try adding this line to the end of your tester function:

Code:
return(true);

Dan


The answers you get are only as good as the information you give!

 
Hi I have this working now.

I am using:

function onSubmit(form)
{
if(form.xTitler.value=='')

{
form.xTitler.value = form.Title.value;
form.xFirstNamer.value = form.FirstName.value;
form.xSecondNamer.value = form.SecondName.value;
form.xHouseNumberr.value = form.HouseNumber.value;
form.xStreet1r.value = form.Street1.value;
form.xTownCityr.value = form.TownCity.value;
form.xWootr.value = form.PostCoder.value;
form.xSwootr.value = form.County.value;
}
}

The problem arose with hidden fields. When I got rid of them it worked.

??


 
You should NOT be using 'form' like that! 'form' is a reserved word, yet you are using it as a parameter (variable) name. The ONLY places the word 'form' should occur is in statements like "this.form".


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top