
Originally Posted by
John
Put these and the textarea all inside a form named, say - 'stringer'. Name the textarea, um - 'theString'.
Lol 
Code:
<script type="text/javascript">
function selectPrintf(frm, opEl, baseStr /*, selectOneName, selectTwoName, selectThreeName, ... */) {
var opStr = baseStr;
for(var i = 3; i < arguments.length; ++i)
opStr = opStr.replace(/%s/, frm.elements[arguments[i]].options[frm.elements[arguments[i]].selectedIndex].text);
frm.elements[opEl].value = opStr;
}
</script>
I'm afraid I had to use regex, but it's a very simple one.
Example of use:
Code:
<form action="" onchange="selectPrintf(this, 'op', 'The %s has got %s windows, a %s and a %s.', 'first', 'second', 'third', 'fourth');">
<select name="first">
<option selected="selected">house</option>
<option>tent</option>
<option>apartment</option>
</select>
<select name="second">
<option selected="selected">seven</option>
<option>five</option>
<option>four</option>
<option>eighteen</option>
</select>
<select name="third">
<option selected="selected">garden</option>
<option>office</option>
<option>bedroom</option>
</select>
<select name="fourth">
<option selected="selected">nursery</option>
<option>playroom</option>
<option>balcony</option>
</select>
<input type="text" name="op" size="80">
</form>
If you want to add more on the same form, just add another of those function calls to the onchange event, remembering to seperate with a semicolon, and change the string and names of the elements.
Bookmarks