Click to See Complete Forum and Search --> : passing value from radio buttons to textarea
tripwater
04-25-2003, 08:30 AM
Hello I have a page that after submit it kicks of an email to the person intended. On this page before submit I give the user the ability to type in a personalized message in a textarea and add that onto the body of the email that is sent by my site.
Now what I want is for my 4 radio buttons that I have on the page when chosen puts a default message in the text area. So if the user sees a message that says what they pretty much need to say they just select it and it populates the textarea and they do not need to type.
here is my code:
<form action=\"../admin/adbuploadsubmit.php\" name=\"emailup\" method=post enctype=\"multipart/form-data\" onSubmit=\"return TheFormCheck()\">
<table border=0 cellpadding=3 cellspacing=5>
<tr>
<td>
<b>Email Message :</b>
</td>
</tr>
<tr>
<td>
<textarea name=\"message\" cols=\"60\" rows=\"15\" wrap=\"VIRTUAL\"></textarea>
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 1> This is my message 1
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 2> This is my message 2
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 3> This is my message 3
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 4> This is my message 4
</td>
</tr>
<tr>
<td>
<input type=submit name=submit value=Submit>
</td>
</tr>
</table>
</form>
Thank you for any help.
khalidali63
04-25-2003, 08:40 AM
1. determine which radio button is checked
As you can see that all the radio button objects have the same name,this createes an array of radio button elements,only you have to loop through the array to find out checked element
for(var x=0;x<document.formName.mymess.length;x++){
//now see which is selected
if(document.formName.mymess[x].checked=="true"){
document.formName.textAreaName.value = desired value here
}
}
tripwater
04-25-2003, 08:44 AM
THank you for the reply.
Where you have
document.formName.textAreaName.value = desired value here
would I set the "desired value here" to my value from my radio buttons? like :
document.formName.textAreaName.value = document.formName.radioName.value
Sorry if this is a stupid question but I am a admitted newbie in JS. Thanks again.
khalidali63
04-25-2003, 08:51 AM
Nothing is stupid...every one has to be a newbie at some point or time...
to your question ,yes thats where you will put the value you want to set in the textarea..
tripwater
04-25-2003, 09:12 AM
sorry to bother again....
I tried this and I think I have it wrong.
<js>
function MessageChange()
{
for(var x = 0; x < document.emailup.mymess.length; x++)
{
//now see which is selected
if(document.emailup.mymess[x].checked==\"true\")
{
document.emailup.message.value = document.emailup.mymess[x].value;
}
}
}
</js>
<form action=\"../admin/adbuploadsubmit.php\" name=\"emailup\" method=post enctype=\"multipart/form-data\" onSubmit=\"return TheFormCheck()\">
<table>
<tr>
<td>
An email is kicked off to each person that you add to SpamnIt's
database. Each email <b>must</b> be replied to (this verifies a
legitimate email address) in order for them to send you email.<p>
Below is a memo field that allows you to personalize what is sent
in the body of the email. This gives you the ability to let the whole list of
people from your address book know who this email is from and encourage
them to reply. <i>Note: to send this as well as the uploaded file, just click
<b>Upload</b> below</i>.<p>
</td>
</tr>
<tr>
<td>
<b>Email Message :</b>
</td>
</tr>
<tr>
<td>
<textarea name=\"message\" cols=\"60\" rows=\"15\" wrap=\"VIRTUAL\"></textarea>
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 1 onClick= return \"MessageChange()\"> This is my message 1
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 2 onClick= return \"MessageChange()\"> This is my message 2
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 3 onClick= return \"MessageChange()\"> This is my message 3
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value=this is my message 4 onClick= return \"MessageChange()\"> This is my message 4
</td>
</tr>
<tr>
<td>
<b>Click Upload below to send this message as well as upload your address book</b>.
</td>
</tr>
</table><p>
I cut the code short but you get the idea. Again thank you for your time.
I think you should try to put your radio buttons' values in quotes. Try to make a habit of doing that, too. In any case, the code shown should work..
khalidali63
04-25-2003, 12:18 PM
here you go...you had several erros in the code..
take a look and one error was mine..:D
I was implementing a wrong comparison.
function MessageChange(){
for(var x = 0; x < document.emailup.mymess.length; x++) {
//now see which is selected
if(document.emailup.mymess[x].checked==true){
document.emailup.message.value = document.emailup.mymess[x].value;
}
}
}
</script>
</head>
<body>
<form action="../admin/adbuploadsubmit.php\" name="emailup" method=post enctype="multipart/form-data" onSubmit="return TheFormCheck()">
<table>
<tr>
<td>
An email is kicked off to each person that you add to SpamnIt's
database. Each email <b>must</b> be replied to (this verifies a
legitimate email address) in order for them to send you email.<p>
Below is a memo field that allows you to personalize what is sent
in the body of the email. This gives you the ability to let the whole list of
people from your address book know who this email is from and encourage
them to reply. <i>Note: to send this as well as the uploaded file, just click
<b>Upload</b> below</i>.<p>
</td>
</tr>
<tr>
<td>
<b>Email Message :</b>
</td>
</tr>
<tr>
<td>
<textarea name="message" cols="60" rows="15" wrap="VIRTUAL"></textarea>
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value="this is my message 1" onClick="return MessageChange()"> This is my message 1
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value="this is my message 2" onClick="return MessageChange()"> This is my message 2
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value="this is my message 3" onClick="return MessageChange()"> This is my message 3
</td>
</tr>
<tr>
<td>
<input type=radio name=mymess value="this is my message 4" onClick="return MessageChange()"> This is my message 4
</td>
</tr>
<tr>
<td>
<b>Click Upload below to send this message as well as upload your address book</b>.
</td>
</tr>
</table><p>
tripwater
04-25-2003, 12:39 PM
OK I put quotes around my radio values and I looked over the new code khalidali63 posted but I could not find anything that had changed...What am I missing?
khalidali63
04-25-2003, 12:50 PM
Copy and paste the code onto your editor,it works.I tested it,and thenspend your time on finding the differences..:D
tripwater
04-25-2003, 12:50 PM
I assume that like the value = hello in a input type text will populate "hello" in the field.
Is this the same for textarea? Because what shows up in textarea field is what falls between the textarea tags.
tripwater
04-25-2003, 12:54 PM
Thank you for your time.
A textarea's value falls between <textarea>value</textarea> rather than an attribute "value=" like <input> tags.