Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > assigning values to a field in HTML document

Reply
Thread Tools

assigning values to a field in HTML document

 
 
Tauqir
Guest
Posts: n/a
 
      01-19-2005
I am trying to do a simple thing: I have these two text fields in an
HTML form. I want to assign the concatenated value to a TEXTAREA. Can
someone help me with the syntax?

<HTML>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
</SCRIPT>
<table ALIGN="center" border="2" width="100%" cellspacing="8"
cellpadding="0">
<FORM action="" method="POST">
<Table border="0" width="75%" cellspacing="0" cellpadding="0"
align="center">
<TR>
<td COLSPAN="1" width="40%"> <LABEL for="firstname">First name:
</LABEL>
</td>
<td COLSPAN="1">
<font face="Verdana" size="1" color="red">*</font>
<INPUT type="text" SIZE="30" NAME="firstname" VALUE= "Tauqir">
</td>
</TR>
<TR>
<td COLSPAN="1" >
<LABEL for="lastname">Last name: </LABEL>
</td>
<td COLSPAN="1">
<font face="Verdana" size="1" color="red">*</font>
<INPUT type="text" SIZE="30" NAME="lastname" VALUE= "Ghani">
</td>
</TR>
<TR>
<td COLSPAN="1">Text Area: </td>
<td COLSPAN="1"> <TEXTAREA Name="Details" COLS="40",
ROWS="5" size="20">
<-- I want to see the concatenated value firstname + lastname as the
value of this text area -->
</TEXTAREA>
<BR>
</td> </TR> <TR>
</TR> <TR>
<td COLSPAN="1">
<font face="Verdana" size="1" color="red">*=Required Fields</font>
</td>
</TR>
</TR>
<TR>
<td COLSPAN="1">
<INPUT type="submit" value="Send" >
<INPUT type="reset" >
</td>
</TR>
</FORM>
</TABLE>
</TABLE>
</HTML>

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      01-19-2005
Tauqir wrote:
> I am trying to do a simple thing: I have these two text fields in an
> HTML form. I want to assign the concatenated value to a TEXTAREA. Can
> someone help me with the syntax?


Your HTML is horrible, please post valid, minimal code (get rid of the
table...) - it makes it much easier to offer help.

When do you want the concatenated value written? I've set it to happen
onchange. I guess you want "Details" to be firstname lastname? Or
lastname, firstname?

[...]
> <INPUT type="text" SIZE="30" NAME="firstname" VALUE= "Tauqir">


<INPUT type="text" SIZE="30" NAME="firstname" VALUE= "Tauqir"
onchange="
this.form.Details.value = this.value + ' '
+ this.form.lastname.value;
">

[...]
> <INPUT type="text" SIZE="30" NAME="lastname" VALUE= "Ghani">


<INPUT type="text" SIZE="30" NAME="lastname" VALUE= "Ghani"
onchange="
this.form.Details.value = this.form.firstname.value + ' '
+ this.value;
">

[...]
> <TEXTAREA Name="Details" COLS="40" ROWS="5" size="20">


<TEXTAREA Name="Details" COLS="40" ROWS="5" size="20"
readonly>Tauqir Ghani</TEXTAREA>

Setting it to readonly means that users can not edit it directly, but
it will still be submitted with the form.

Note that the onchange only fires when the text inputs lose focus, you
may want to set it to fire on some other event.

Fully functional code below:

<HTML>
<head><title>play</title>
</head><body>

<FORM action="" method="POST">
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" SIZE="30" NAME="firstname" VALUE= "Tauqir"
onchange="
this.form.Details.value = this.value + ' '
+ this.form.lastname.value;
">
<br>
<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" SIZE="30" NAME="lastname" VALUE= "Ghani"
onchange="
this.form.Details.value = this.form.firstname.value + ' '
+ this.value;
">
<br>
<TEXTAREA Name="Details" COLS="40" ROWS="5" size="20"
readonly>Tauqir Ghani</TEXTAREA>
<br>
<INPUT type="submit" value="Send" >
<INPUT type="reset" >
</FORM>
</body></HTML>



--
Rob
 
Reply With Quote
 
 
 
 
Tauqir
Guest
Posts: n/a
 
      01-19-2005
Thanks, and yes I admit the frivolous posting style. It was the first
time I used a newsgroup to ask for help. Hope to repay by helping
others.

 
Reply With Quote
 
Tauqir
Guest
Posts: n/a
 
      01-19-2005
Thanks, gets me over the hump.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven Javascript 3 05-13-2004 12:15 AM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven ASP General 3 05-13-2004 12:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57