Click to See Complete Forum and Search --> : Concatenating input values


Orsen Cart
08-31-2004, 01:46 PM
Hi

I've searched the forum but couldn't find an answer to my specific question so I would apreciate a little help.

I have a <form> with two values. When I submit the form, I want to submit it with one value which is a concatenation of the other two.

e.g.
<form name="pay" action="https://etc" method=post>
<input type="text" name="email">
<input type="text" name="surname">
<input type =hidden" name="concatstring">
<input type="submit" value="buttontext">
</form>

I've tried

<form name="pay" action="https://etc" method=post>
<input type="text" name="email">
<input type="text" name="surname">
<script...>
document.pay.concatstring.value=document.pay.email.value+document.pay.surname.value
</script>
<input type="submit" value="buttontext">

but I can't get it working. I think I may have it all in the wrong order etc.

Any help would be much appreciated.

javascript
but I think I may have got it all in the wrong order. Have

gil davis
08-31-2004, 02:01 PM
You need to tie your script to the onsubmit handler for the form. You can't just plop a script into the middle of the form.
<form name="pay" action="https://etc" method=post onsubmit="this.concatstring.value = this.email.value + this.surname.value">
<input type="text" name="email">
<input type="text" name="surname">
<input type =hidden" name="concatstring">
<input type="submit" value="buttontext">
</form>

steelersfan88
08-31-2004, 02:03 PM
Originally posted by gil davis
<form name="pay" action="https://etc" method=post onsubmit="this.concatstring.value = this.email.value + this.surname.value">
<input type="text" name="email">
<input type="text" name="surname">
<input type="hidden" name="concatstring">
<input type="submit" value="buttontext">
</form> Missing quote ;)

Orsen Cart
08-31-2004, 06:02 PM
That's great guys, thank you very much.

:D

Orsen Cart
09-01-2004, 06:59 PM
Hi again

I have used the following ...

this.concatstring.value = this.email.value + this.surname.value

as suggested and that worked well. I also wish to format this with some additional text (which I have been able to do) and some line feeds (which I cannot do).

"Email:"+this.email.value+" Surname:"+this.surname.value
will give me .....

Email:fred@bloggs.com Surname:Bloggs

but how could I make it look like .....

Email:fred@bloggs.com
Surname:Bloggs

What do I use, and where, to specify that line feed? (\n didn't work)
TIA

gil davis
09-01-2004, 08:12 PM
It depends on what the target is. Are you trying to make an e-mail or a web page?

If it is e-mail, is it HTML e-mail? If so, use "<br>".

steelersfan88
09-01-2004, 10:36 PM
Add %0d for a line break.

Orsen Cart
09-02-2004, 07:26 AM
Hi guys

Sorry, I should have mentioned that the form will be submitted to another webpage where it will be displayed within a multi-line text box (presumably a textarea). I would like to format that text so it is easier to read.

Many thanks

steelersfan88
09-02-2004, 11:01 AM
In a text box, a line break is \n. In an email, you can use %0d.

Orsen Cart
09-02-2004, 02:17 PM
Hi

I'd already tried \n and it didn't work. On viewing the source of the target website I can now see that the text area contains all of the included text but appears to have stripped out the \n characters so I guess there is nothing I can do about that.

Thanks for your help

Orsen Cart
09-02-2004, 02:24 PM
Oh, forgot to add that if I then edit that generated source file and insert the \n character manually, save the file locally and run it, the \n character is actually displayed in the text rather than interpreted as a linefeed.