0

Possible Duplicate:
How to set the JSTL variable value in javascript?

I have certain codes as following:

    <c:set var="test" scope="page" value="0"/>
    <script type="text/javascript">
    var time;

    function Check(){
       if(time <= 0)
       {
           <c:set var="test" scope="page" value="1"/>         
       }
      time-=1;
    }
    </script>   

when I did

      <c:out value="${test}"/> 

it seems that its value's always 1 and it happened before time=0 or less than 0. And also did something below:

      <c:if test="${test=='1'}">
        <sql:transaction dataSource="${dataBase}">
          <sql:update var="tDel">
               DELETE FROM tmp_time WHERE username='${username}'
          </sql:update>
        </sql:transaction>
     </c:if>

It always comes to DELETE at the first time and not wait till time=0 or less. Can anyone help me out?

4
  • @ArtemKoshelev:Perhaps, but it's not the same. CMIIW Commented Dec 10, 2012 at 5:15
  • All of the server-side code executes on the server before the browser sees it. So JavaScript can't set a JSTL variable value at all. If you want a client-side countdown in JS before a server-side operation such as a database deletion you will need to make an Ajax request when the time is up. Note that time-=; is a syntax error, and given that you don't initialise time when you then test it with if(time <= 0) that condition will always be false. Commented Dec 10, 2012 at 5:33
  • @nnnnnn:Sorry, i just edited my codes. Commented Dec 10, 2012 at 5:34
  • P.S. If you use your browser's View Page Source option you'll see why the above code didn't work to try to access JSTL stuff from JS. Commented Dec 10, 2012 at 5:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.