Hi I have a question, it's probably very basic but I'm still learning the Javascript basics.
The following form outputs a string change (from "input" to "text" box ). When the word "test" is inputted, it changes to "good".
Simple question: If there is no matching string, how would I get the form to just display nothing at all?
Thanks!
[HTML]
<html>
<head>
<center>
<script type = "text/javascript">
function replaceChars() {
var temp = document.subform.input.value;
temp = temp.replace(/test/gi, "good");
temp = temp.replace (/hello/gi, "bad");
temp = temp.replace (/today/gi, "tomorrow");
document.subform.text.value = temp;
}
</script>
</head>
<body>
<form name="subform">
<FONT size=+2>
<textarea rows="8" name="input" cols="34" value=""></textarea></FONT>
<br><br>
<input type=button name=action value="Change" onClick="replaceChars(document.subform.input.value );">
<input type="reset" value="Reset" name="B2">
<br><br>
<table border="1" width="30%" id="table1" height="68" bgcolor="#FFFFFF">
<tr>
<td align="center" width="70"><INPUT TYPE="button" NAME="t" VALUE=" t " OnClick="subform.input.value += 't'"></td>
<td align="center" width="70"><INPUT TYPE="button" NAME="e" VALUE=" e " OnClick="subform.input.value += 'e'"></td>
<td align="center" width="70"><INPUT TYPE="button" NAME="s" VALUE=" s " OnClick="subform.input.value += 's'"></td>
<td align="center" width="70"><INPUT TYPE="button" NAME="t" VALUE=" t " OnClick="subform.input.value += 't'"></td> </tr>
</table>
<br><br>
<textarea rows="8" name="text" cols="34" value=""></textarea>
</form>
</center>
</body>
</html>[/HTML]