calling javascript function in JSP
843835Jun 6 2002 — edited Jun 7 2002Hi ,
I am trying to call a javascript function in JSP to enable/disable a button in form depending on certain conditions.
It seems that my function gets exceuted and enables/disables buttons properly when I come back to page if it is in place 2. If I put it in place 1, it does not seem to get executed.
Page loads OK in both case 1 &2.
I am not clear what is happening and what's the logic behind this.
Thanks in advance.
Following is the sample of what I am trying to do
<script>
function EnableValidateBtn()
{
top.document.forms[0].elements['btnValidateShippingAddress'].disabled = false;
}
function DisableValidateBtn()
{
top.document.forms[0].elements['btnValidateShippingAddress'].disabled = true;
top.document.forms[0].elements['txtAddrValidated'].value = "0";
}
function SetValidateBtn()
{
<% if ( some condition)
{%>
DisableValidateBtn();
<%}
else {%>
EnableValidateBtn();
<%}
}
</script>
<html>
<body onFocus="closeCal()" bgcolor="#999999" class=linkColor Topmargin="0" Leftmargin="0">
<form name="form" method="POST" action="/go">
-------- some code ------------
<input type="button" name="btnValidateShippingAddress" value="Validate Shipping Address" onClick="javascript:doValidateShippingAddress()">
<script>
// place 1 SetValidateBtn();
</script>
</form>
</body>
<script>
//place 2 SetValidateBtn();
</script>
</html>