PDA

View Full Version : Fill a text box from a droplist



mhodgson
06-20-2008, 12:13 PM
Hi, I wonder if anyone can help on this problem.

I have a text box that users can type into, occasionally I want them to insert a preset bit of text (e.g. <<name>> or <<DoB>>) selected from a droplist.

This will then be replaced with data from a database in a mailmerge type of thing which is why I need preselected text inserts. I can do the replacing bit fine (using PHP). I just can't work out the javascript for the other, inserting, bit.

Nile
06-20-2008, 01:25 PM
Please post a link to the page on your site that contains the problematic script so we can check it out.
Please include your code so that we can take a look at it, we can't do much without it.

mhodgson
06-23-2008, 12:00 PM
I fiddled and played with a script I found and here is what I came up with.
Seems to work exactly as I want so I thought I would post it in case it might help anyone else.
It alows you to type and add preset text values (in my case field names for merging with a list).


<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><form name="merge_letter"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><select name="selectdatafield" size="1" onChange="addcontent(this)">
<option selected >Select fields</option>
<option value=" <<name>> ">Name</option>
<option value=" <<DoB>> ">DoB</option>
<option value=" <<class>> ">Class</option>
<option value=" <<literacy>> ">Literacy</option>
</select><br>
</td>
</tr>
<tr>
<td width="100%"><textarea rows="8" name="contentbox" cols="35" wrap="virtual"></textarea><br>
<font face="arial" size="-2">This free script provided by <a href="http://wsabstract.com">Website Abstraction</a></font>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>

<script language="JavaScript">
//Function to add words to a text area
function addcontent(which){
document.merge_letter.contentbox.value=document.merge_letter.contentbox.value+which.value
}
</script>