javascript - how to prevent the jsp to execute -
var answer = confirm("do want save?"); alert(answer); if(answer==true){ <% session.setattribute("confirm", "true"); %> }else if(answer==false){ <% session.setattribute("confirm", "false"); %> }
what wrong code? made confirm dialog. whenever clicked cancel button, set attribute of confirm false. when clicked ok, did codes inside true condition did jsp code inside false condition. ignore condition. tell me whats wrong?
the jsp executed on server before javascript runs on browser (before sent browser).
for server-side execution, javascript ignored. part of output, html.
all server sees is:
jspout.write("var answer = ......... "); session.setattribute("confirm", "true"); jspout.write("} else if ..... "); session.setattribute("confirm", "false");
as can see, there no conditional execution here @ all.
if want interact server javascript, have make new request transmit , receive data. example using ajax. or posting form.