Jump to content

Populate Textarea via dropdown - Best method?


Greymon

Recommended Posts

Hi all,

 

I am working with a drop down to auto populate a textarea with preset fields / lines. The issue I keep having is the formatting to the text being populated has no lines/breaks to it. Below is the current java script snip it and the form as it stands. I am looking to find if there would be a better method to doing this, including creating a php form utlizing ajax to pull the information. Thoughts?

 

Javascript:

<script type="text/javascript">function updateTextBox(val)
{
if(val == "1")
{
document.forms['Form'].elements['TextBox'].value = "Line 1, Line 2, Line 3, Line 4";<--- In theory should display as entered, however this does not occur on any line break/Also /n/p/br/&nbsp do not work to adding lines/breaks.
}
else if(val == "2")
{
document.forms['Form'].elements['TextBox'].value = "Line 1 &nbsp Line 2";
}
}


</script>

 

 

Form:

<form name="Form">
<select onchange='updateTextBox(this.value)'>
<option value=""></option>
<option value="1">Test</option>
<option value="2">Test2</option>
</select>
<tr>
<td> <div align="left"><span id="copy">
 <textarea name="TextBox" cols="29" rows="30" style="font-family: Verdana" class="size12"></textarea>
 <br />
</span></div>
<table width="20%" border="0" align="left">
	<tr><td><input name="Button" type="button" onclick="javascript:selectcopy('Form.textbox')" value="Copy Notes" /></td></tr>
	<tr><td><input name="RESET" type="RESET" value="Clear Notes" /></td></tr>
</table>
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.