View Full Version : Checking for existence of certain text?

07-12-2005, 09:19 PM
I'm using this onclick event below:

onClick="javascript:modify('text value here');" href="#" onFocus="if(this.blur)this.blur()">Click Here</a>

I use this to load whatever text value there is into a text box area, but was wondering if there was a way I could check for the existence of a certain piece of text & if found it would load some different pre-specified text instead into the text box field?


Mr J
07-12-2005, 09:28 PM
Please try the following example

<script type="text/javascript">
function modify(str){
if(str.indexOf("text value here")!=-1){
document.forms["myForm"]["t1"].value="New String"


<a href="#null" onclick="modify('text value here')">Click Here</a>
<a href="#null" onclick="modify('Hello World')">And Here</a>

<form name="myForm">
<input type="text" name="t1">