Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

javascript with ASP.NET question

I have a js which makes sure a value is entered when the submit button is clicked (Which works fine!)But my problem is that i'm posting the page to another page as you can see in the FORM tag.
When i click the button it validates and pops up the javascropt page but when i click OK it doesn't retain me on that page it STILL goes to the page
"Search.aspx" and then it displays the search result which i don't want .What i want is for it to retain on the page if no value is typed in..
Any ideas:-
<script language="javascript">
function isValidate()
{
//valid = true;
if (document.frmSearch.txtSearch.value == "")
{
alert ("Insert a Value.");

// valid = false;
}
//return valid;
}
</script>

</table>

<form method="post" action="Search.aspx" name="frmSearch" id="frmSearch">
<td align="left">
<input type="text" ID="txtSearch" SIZE="20">
</td>
<td align="left">
<input type="button" id="image1" alt="Click to Search" onclick="return isValidate();" value="Search">
</td>
</form>
[1328 byte] By [naijacoder] at [2007-11-11 7:05:17]
# 1 Re: javascript with ASP.NET question
Your isValidate function does not return a value. Have you tried having it return false if the form is invalid?
Phil Weber at 2007-11-11 23:14:04 >
# 2 Re: javascript with ASP.NET question
Phil thanks for the reply but if i set it to return false when its invalid it works.
But if i input a value and click the submit button it doesn't FIRE..
What am i missing here?
Thanks
naijacoder at 2007-11-11 23:15:04 >
# 3 Re: javascript with ASP.NET question
When using the input type="text i noticed if i reference the ID="txtSearch" in my code its doesn't post the parameter to the page i'm posting to but it works if i use name="txtSearch".
Any ideas why that works that way?
naijacoder at 2007-11-11 23:16:03 >
# 4 Re: javascript with ASP.NET question
Thx phil fixed it.
Patrick
naijacoder at 2007-11-11 23:17:04 >