DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  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-28-2002, 11:14 PM
  2. Replies: 0
    Last Post: 06-15-2002, 09:03 AM
  3. recordset and connection question...
    By Sok in forum VB Classic
    Replies: 2
    Last Post: 02-09-2001, 12:28 PM
  4. VB,STORED PROC, COM, DTC QUESTION?
    By melvin ng in forum VB Classic
    Replies: 1
    Last Post: 11-10-2000, 03:46 AM
  5. Re: Passing an object name through a variable
    By mrfelis in forum VB Classic
    Replies: 9
    Last Post: 04-25-2000, 10:08 PM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links