...

View Full Version : "sentance generator"



7111
10-18-2006, 11:33 AM
I am trying to make a form that will insert strings entered into textfields into a sentance. I've accomplished this, but I don't know how to use a checkbox to toggle an extra, fixed word in the textarea.

For example, if 'a' was "," & 'b' was "and", the output would be "Beginning, middle and end."

But how do I make it output "Beginning, middle and end." only if 'c' is left unchecked, and "Beginning, middle and the end." when 'c' IS checked?


<html><head>
<script type="text/javascript">
function createtext() {
output.value= "Beginning"+
a.value+
" middle "+
b.value+
" end.";
}
</script></head><body><form>
Beginning<br>
<input type="text" id="a"><br>
middle<br>
<input type="text" id="b"><br>
<input type="checkbox" id="c">the<br>
end.<br>
<input type="button" onClick="createtext();" value="submit"><br>
<textarea id="output"></textarea>
</form></body></html>

Thanks in advance.

jalarie
10-18-2006, 04:14 PM
Try this:


function createtext() {
if (document.forms.c.checked) { c=' the '; } else { c=''; }
output.value= "Beginning"+
a.value+
" middle "+
b.value+c+
" end.";
}

7111
10-18-2006, 11:03 PM
That didn't work, but I got some help from another forum, and the following worked perfectly:
<script type="text/javascript">
function createtext() {
if (c.checked == 1) {document.forms['z'].elements['the'].value = "the";}
else {document.forms['z'].elements['the'].value = " ";}
output.value= "Beginning" + a.value + " middle " + b.value + " " + the.value + " end.";
}
</script>
<form name='z'>
<input type="hidden" id="the">
Beginning<br>
<input type="text" id="a"><br>
middle<br>
<input type="text" id="b"><br>
<input type="checkbox" id="c">the<br>
end.<br>
<input type="button" onClick="createtext();" value="CLICK ME"><br>
<textarea id="output"></textarea>
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum