-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.

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks brother. I am using ajax in my project
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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.