You need to be mindful of the difference between JavaScript and the JSP Java
code. The OnClick handler of the input tag is part of JavaScript. You can
call a JavaScript function and set a JavaScript variable. You can't really
set a Java variable from inside a JavaScript function, because the two are
completely different. Remember that a JSP gets compiled into a servlet. The
Java code lives on the server and is executed at page display time. The
JavaScript lives inside the page itself and gets executed on the browser (in
this case in response to a click action). You can use the Java to
conditionally create the JavaScript, and/or to set JavaScript variables in
response to Java queries, but you can't really do it the other way around.

I'm not exactly sure, based on the snippets you include here, what you're
really trying to achieve or where that JSP code that queries _X gets used,
but if what you're trying to do is to somewhere conditionally output a
button based on whether the user clicked something in a previous page, the
better way is to have the OnClick handler call a JavaScript function that
sets a hidden form field, and then in place of the "if (_X = 1)" (which, by
the way, should really be "=="), test for the existence of that hidden
parameter.

--Jim Preston


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Henki Lubis
Sent: Thursday, July 13, 2000 11:57 PM
To: [EMAIL PROTECTED]
Subject: hOW to declare a variable


Guys .. how can i declare a variable and set it to 1 if the image has been
clicked ???

this is the listing
<INPUT  TYPE="image"
        SRC="/admin/images/goes.gif"
        VALIGN="top"
        WIDTH="36"
        HEIGHT="23"
        ALT="Search for Stocks"
        BORDER="0"
        ONCLICK="Search(); return false;">

i try like this but not working .. ONCLICK="Search; return false; <% int _X
= 1 %>">

i wanna use the _X like this if the var work :

<tr><td>
             <% search=request.getParameter("search");%>
                 <% if (_X = 1){%>
                <input type="button" value="Add"
onclick="AddList('<%=search%>','<%=szFreq%>');">
                <%}else
                {%><input type="button" value="Add" disabled><%}%>
</td></tr>


reagrds

a Beginner

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to