473,411 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

assigning values to a field in HTML document

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>

Jul 23 '05 #1
4 2258

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?

<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>


document.getElementsByName("Details").value =
document.getElementsByName("firstname").value +
document.getElementsByName("lastname").value

Jul 23 '05 #2
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
Jul 23 '05 #3
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.

Jul 23 '05 #4
Thanks, gets me over the hump.

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bhavin G | last post by:
Hi there , I am pretty new at javascripting and i am having this huge problem. I am using asp.net and C# webapplication. In my asp.net aspx file I have a place holder for taking an html table...
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
2
by: Gawie Marais | last post by:
hi all, i have a form and would like to check two fields. if field 1 containes the letter 'c' and the other field contains 'undefined', then an error should apprear ina box on the screen. can...
1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
3
by: | last post by:
T.I.A. to whomever replys... I'm new to ASP. I'm reading input from a flat-file (not a DB) using a vbscript routine to display on an ASP form so that a user can update the info, submitting the...
5
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
4
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.