I've been stuck on this for days, and am hoping someone can help. On our webpage, there is a search box which is an input type="text" box. Due to some fatal errors on the page that happen if someone does NOT put in a keyword to search for, I want to make it impossible for the search to take place unless there is a keyword and instead popup an alert. I need for this to work both if they click on the "go" image and if they hit enter. There are also other forms on the page, so I can't just disable the enter key entirely. I tried the following code to at least try to have it work if they click on the "go" image, but that's not even working right
If anyone could help I'd really appreciate it.
{literal}
<script language="javascript">
<!--
function Validate()
{
for (i=0;i<document.forms[0].elements.length;i++)
{
if (document.forms[0].elements.value=="")
{
alert("Please enter a keyword in the search box ");
document.forms[0].elements.focus();
return false ;
}
else {
document.productsearchform.submit();
}
}
}
//-->
</script>
{/literal}
then around the go image:
<form method="get" action="search.php" name=productsearchform>
<tr>
<td valign="middle" class="WhiteLine" width=70>
<p>
<span class="TableTopLabel">
{$lng.lbl_search}:
</span></p>
</td>
<td valign="middle" class="WhiteLine">
<input type="text" name="substring" size="12"
value="{$smarty.get.substring|escape}">
<span class="TableCenterProductPriceBlue">
<a onclick="java script:Validate()" href=http://www.webdeveloper.com/forum/archive/index.php/"#">
<img src="../{ #ImagesDir# }
/GOboutonWhiteBkg.gif" width=28 height=13
border=0 align=top></a>
</span>
</td>
</tr>
Any suggestions?
If anyone could help I'd really appreciate it.
{literal}
<script language="javascript">
<!--
function Validate()
{
for (i=0;i<document.forms[0].elements.length;i++)
{
if (document.forms[0].elements.value=="")
{
alert("Please enter a keyword in the search box ");
document.forms[0].elements.focus();
return false ;
}
else {
document.productsearchform.submit();
}
}
}
//-->
</script>
{/literal}
then around the go image:
<form method="get" action="search.php" name=productsearchform>
<tr>
<td valign="middle" class="WhiteLine" width=70>
<p>
<span class="TableTopLabel">
{$lng.lbl_search}:
</span></p>
</td>
<td valign="middle" class="WhiteLine">
<input type="text" name="substring" size="12"
value="{$smarty.get.substring|escape}">
<span class="TableCenterProductPriceBlue">
<a onclick="java script:Validate()" href=http://www.webdeveloper.com/forum/archive/index.php/"#">
<img src="../{ #ImagesDir# }
/GOboutonWhiteBkg.gif" width=28 height=13
border=0 align=top></a>
</span>
</td>
</tr>
Any suggestions?