JSP/Global Variable Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: JSP/Global Variable Question

  1. #1
    Join Date
    Mar 2006
    Posts
    100

    JSP/Global Variable Question

    This is the code but it shows 0 everytime. Why doesn't it increment?

    Code:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <%
    	int testVar = 0;
    %>
    <script type="text/javascript">
    function testFun()
    {
    	<%testVar=testVar++;%>
    	alert("Worked");
    	document.forms[0].test.value=<%=testVar%>;
    }
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form>
    <input id="test" value=<%=testVar%>></input>
    <input type="button" id="btnGo" onClick="testFun()" value="Click Here!"></input>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    35
    <%testVar=testVar++;%>

    should be

    <%testVar=testVar++%>

    no semi-colon '; '

  3. #3
    Join Date
    Mar 2006
    Posts
    100
    Actually that causes it to have a compile error I think it has something to do with needing to only declare the variable
    <%
    int testVar = 0;
    %>
    When not a postback and on load or something like that but I am not sure anyone else know?

  4. #4
    Join Date
    Oct 2006
    Posts
    9
    I think you have to use declaration instead of a scriptlet.

    that should be like <%!testVar=testVar++%>

    try this

Similar Threads

  1. Replies: 2
    Last Post: 07-29-2002, 12:14 AM
  2. Replies: 0
    Last Post: 06-15-2002, 10:03 AM
  3. recordset and connection question...
    By Sok in forum VB Classic
    Replies: 2
    Last Post: 02-09-2001, 01:28 PM
  4. VB,STORED PROC, COM, DTC QUESTION?
    By melvin ng in forum VB Classic
    Replies: 1
    Last Post: 11-10-2000, 04:46 AM
  5. Re: Passing an object name through a variable
    By mrfelis in forum VB Classic
    Replies: 9
    Last Post: 04-25-2000, 11:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center