So what I have is a simple search form and submit button. What I want to do is validate the input to determine whether or not an “=” was included in the search query, if so then I want it to send the input string (que) to vert.php. If not then I would like it to send to search.php.
<script type="text/javascript" language="JavaScript">
function chgact()
{
if(document.myform.que.indexOf(=) == true) {
document.myform.action = '/vert.php';
}
return true;
}
</script>
<h1>Keyword search</h1>
<form name="myform" method="post" action="/search.php" onSubmit="return chgact()">
Keywords: <br/>
<input type="text" name="que" id="que" / >
<p/>
Items to display: <br/>
<select name="i">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
<p/>
<input type="submit" name="submit" value="Search"/>
</form>
Any help at all would be so grealty appreciated! 🙂
Change line 4 to
if (document.myform.que.value.indexOf('=') != -1) {You need to get the value of que, you need to enquote the equals sign (you’re searching for the character ‘=’), and the
indexOffunction returns either -1 if not found or the position of the first occurrence, which is an integer. It does not return a boolean value.Here is the updated code: