No.  Server side code can NEVER interract with client side - HTTP is a
stateless protocol.

However, if you have a need to inform your server when a client does
something on a page you can use the frames page workaround.  It works like
this :


FRAMES.JSP      - this page sets up a frameset where one frame is invisible
(0 pixels high)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~
<html>
        <head>
                <title>Frames Page</title>
        </head>

        <frameset rows="*, 0">
                <frame name="frameMain" src="form.jsp">
                <frame name="frameServer" src="server.jsp">
        </frameset>
</html>


FORM.JSP        - this page contains your form, which you want to have
inspected by the server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~
<html>
        <head>
                <title>Form Page</title>

                <script language="JavaScript">
                        function changeCity(oSelect)
                        {
                                cityValue =
oSelect.options[oSelect.selectedIndex].value;

                                // you can take out this alert line
                                // it simply pops up a box telling you what
was selected
                                alert(cityValue);

                                // this is the line that updates your hidden
"server" page
                                top.frameServer.location.href =
"server.jsp?city=" + cityValue;
                        }
                </script>
        </head>

        <body>
                Welcome to my form page!<br>
                <br>
                <form action="something.jsp" method="POST">
                        <select name="cityList"
onchange="changeCity(this);">
                                <option value="MEL">Melbourne
                                <option value="SYD">Sydney
                                <option value="HO">Hobart
                        </select>
                        <br>
                        <input type="submit" value="Submit">
                </form>
        </body>
</html>


SERVER.JSP
~~~~~~~~~~~~~~~~~
<html>
        <head>
                <title>Server page</title>

                <%      // Here you need to put some JSP that will accept
the GET method used in the URL
                        // passed from the FORM.JSP page in the JavaScript
function changeCity()
                %>
        </head>
</html>



The end result of all this is that you have a page that looks normal, but is
really a frameset with an invisible page down the bottom (0 pixels high)
that can be used to trigger and perform server side code without having to
lose or change your form page.  The actual course of events is like this:

1.> User clicks on the cityList select box in the FORM.JSP page and chooses
a different value.
2.> An onchange event is fired for the cityList select box in the FORM.JSP
page.
3.> Because the onchange event for the cityList select box points to the
changeCity() function it gets executed
4.> The changeCity function extracts the selected VALUE from the cityList
select box.
5.> The changeCity function creates a URL from the extracted VALUE and
points the frameServer frame to that URL.
6.> The SERVER.JSP page in the frameServer frame does whatever you want with
the passed values.

This is nifty if you want to dynamically update values in select boxes etc
by updating their OPTIONS values, but that goes beyond the scope of this
explanation - learn more about JavaScript if you want to do that.

Hope this helps!



-----Original Message-----
From: Garg Sanjay [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 09, 1999 8:17 AM
To: [EMAIL PROTECTED]
Subject: Visibility of form element values to JSP scriptlet


Hi all,

I was wondering whether the form element's values are directly
visible to the JSP scriptlet within the same page. For example
say I have a ComboBox and onChange event for the combo I want
that the JSP scriptlet within the JavaScript should be able to
see the selected combo item's value.
Is it possible. I would appreciate any input.

Regards,
Sanjay

-----
Sent using MailStart.com ( http://MailStart.Com/welcome.html )
The FREE way to access your mailbox via any web browser, anywhere!

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to