-1
<script language="javascript"> 
var counter=0; 
var i=1;
function saveclick() 
{ 
<%j++;%>

    if(counter==3)
    { 
alert(counter);

}


else {

document.getElementById("error").innerHTML ="<%=qarr[j]%>"

  }
}

</script>

here i am using a qarr an array of String and its return String of corresponding index of array. But when i click on button this javascripts' saveclick function execute but innerhtml shows only one String all times. I want that when i click on button then js function execute and every time new String appear in innerHtml. please do needful in this matter.

hemant
  • 173
  • 2
  • 9

3 Answers3

1

Jsp plays on server side and javascript plays on client side.

Java needs compiled code and Javascript is just a scripting language interpreted by the browser.

You need to either make a request to server(HTML forms/AJAX) for new content or Maintain Json object in client side itself while page loading and use it later.

But You cannot mix them.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

The JSP page is returned from the server as HTML page containing Javascript. The data from the server is returned only once. You can return a single string from the server with a separator, and then parse it in Client side (Javascript). You can also send data back and forth between the server and client, using some Ajax for example.

Mansuro
  • 4,558
  • 4
  • 36
  • 76
0

You can execute jsp from your javascript function by implementing ajax method.

vusan
  • 5,221
  • 4
  • 46
  • 81