javascript - How to disable a button from 'if' condition in jsp -
i have method processsots trying invoke submit button, when diasble onclick element. not calling method. 1 me how call method after disabling submit button
<table> <tr> <td width=150> </td> <td width="1999"> <h1 align='left'>please click on button process sots feed file</h1> <form name="sotstestorderfoler" > <br> <input type="submit" name="username" value="process feed file" onclick="this.disabled='disabled';> </form> </td> </tr> </table> <% if ( request.getparameter("username") != null ) { processsots(); } %>
(code tried onsubmit
)
<form name="sotstestorderfoler" method="post" onsubmit="foo()" > <script type="text/javascript"> function foo() { sotstestorderfoler.username.disabled=true; <%processsots();%> return true; } </script> </form>
i use onsubmit
of form disable button, these answers illustrate:
realize jsp code server-side , javascript client-side, can't directly interact each other.
you mixing jsp code , javascript. jsp code executed on server. when browser requests webpage, jsp code executed in order build webpage. means starts writing out things <script type="text/javascript">
, function foo()
stream send browser. when reaches <%processsots();%>
, doesn't write out text, calls method processsots()
. write out return value of processots()
. means method executed before users see page or try push submit button.
this mistake many new jsp programmers make; jsp code cannot executed while javascript executing. way javascript code interact jsp code via http requests, in form of ajax call or form submit.
instead of trying call jsp method in javascript, must have form submit servlet can call processsots()
, return result http response.
Comments
Post a Comment