PDA

View Full Version : How can I pass several form values together to one textbox with just one click?



green
06-06-2006, 06:35 PM
Hi,

I'm trying to design a tool for learners of Spanish which compiles a series of Spanish phrases to create completed letters. The first part I have done and the user is finally presented with a number of separate textboxes each one with one phrase (in order) of the completed letter.

For example: 1st box "Hola,"; 2nd box "¿qué tal?" etc. etc.

(Code:
<form name="yourform1">
<p style="font-family:Arial,sans-serif; font-size:10pt; margin-top:1; margin-bottom:1;" align="left"><font face="Arial"><span style="font-size:10pt;">
<input type=text name=msgs1 size="28" style="background-color:rgb(247,225,213); border-style:none;">
&nbsp;&nbsp;<input type=text name=msgs2 size="28" style="background-color:rgb(247,225,213); border-style:none;"></span></font></p>
</form>

My question is: HOW CAN I SEND ALL those values (all phrases together) to one textbox so they appear in an easily copiable final letter eg.:

Final letter textbox: Hola, ¿Qué tal? etc. etc.

(Code:
<form name="form10">
<p><textarea name="complete_letter" rows="20" cols="50"></textarea></p>
</form>)

Of course, the user could copy the values one by one but I'm looking for a one click alternative eg. highlighting all textboxes together and then copy and paste to final textbox, (or is that impossible?) or a passText function.

Is there any way to do this? I'd greatly appreciate anyone's help?
(Please talk to me like a beginner programmer!!!)

Regards, Green

Twey
06-06-2006, 07:20 PM
<form action="" onsubmit="this.elements['complete_letter'].value = '';for(var i=0;i<this.elements.length;i++) if(this.elements[i].class.indexOf('es') != -1) this.elements['complete_letter'].value += (i == 0 ? '' : ' ') + this.elements[i].value;return false;">

green
06-07-2006, 02:24 PM
Thank you for that but I can't get it to work! :confused:

Here is a simplified version of my page. The idea is that on the button click any values written in the first two fields should be shown, together, (as though continuous text) in the large textbox (without clearing the first two fields). Also I need to be able to add more fields in the first form and the result on click should always be that ALL the values are shown together in the textbox. ie. the phrases that make up the letter in the first form fields are displayed as continuous text in the textbox below.

<html>
<head>

<form name="yourform1">
<p align="left" style="font-family:Arial,sans-serif; font-size:10pt; margin-top:1; margin-bottom:1;">
<font face="Arial"><span style="font-size:10pt;">
<input type=text name=msgs1 size="28" style="background-color:rgb(247,225,213); border-style:none;" value=" ">
<input type=text name=msgs2 size="28" style="background-color:rgb(247,225,213); border-style:none;" value=" ">
</span>
<input type="submit" name="go" value="send"></font>
</form>

<form name="form10">
<p><font face="Arial">
<textarea name="complete_letter" rows="20" cols="50">
</textarea></font></p>
</form>

</body>
</html>

Regards, Green

Twey
06-07-2006, 03:53 PM
Ah, without clearing the previous content?
<form action="" onsubmit="for(var i=0;i<this.elements.length;i++) if(this.elements[i].class.indexOf('es') != -1) this.elements['complete_letter'].value += (i == 0 ? '' : ' ') + this.elements[i].value;return false;">

green
06-07-2006, 05:53 PM
Not having any joy! :(
Would you do me the great favour of inserting your code in my code from my previous post?

Regards

Green

Twey
06-07-2006, 06:40 PM
<form onsubmit="if(this.elements['complete_letter'].value != '') this.elements['complete_letter'].value += ' ';for(var i=0;i<this.elements.length;i++) if(this.elements[i].className.indexOf('es') != -1) this.elements['complete_letter'].value += (i == 0 ? '' : ' ') + this.elements[i].value;return false;" action="">
<p style="font-family:Arial,sans-serif; font-size:110%; margin-top:1; margin-bottom:1;text-align:left;font-family:Arial sans-serif;">
<input type=text name=msgs1 size="28" style="background-color:rgb(247,225,213); border-style:none;" class="es">
<input type=text name=msgs2 size="28" style="background-color:rgb(247,225,213); border-style:none;" class="es">
<input type="submit" name="go" value="send"><br>
<textarea name="complete_letter" rows="20" cols="50"></textarea>
</p>
</form>I started cleaning up your code, then got bored and stopped.

green
06-08-2006, 04:21 PM
But that works just fine now. I have added more boxes and the effect is the same. I REALLY am grateful :) . This Spanish letter writer is still going to take me weeks to complete. But when I'm through I'll send you a free copy for download. Thanks again, Twey. :) :)