title: javascript with jsp
body: <p>Ok its a continuation of my crap attempts of using client side scripts along with server side elements.</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form name="test" action="test.jsp" method="post" enctype="multipart/form-data"&gt;
  &lt;select name="harish" onchange=callme();&gt;
  &lt;option value="1"&gt;1&lt;/option&gt;
  &lt;option value="2"&gt;2&lt;/option&gt;
  &lt;/select&gt;
  &lt;script&gt; 
  var jsvar="Hello";
  function callme()
  {
      alert(jsvar);
      jsvar=document.getElementById("harish").value;
      alert(jsvar);
  }
  &lt;/script&gt; 
   &lt;% 
   String s=(String)("&lt;script&gt;document.writeln(jsvar)&lt;/script&gt;").toString();
   out.println(s.equals("Hello"));
   if(!(s.equals("Hello")))
   {
   String jspvar="&lt;script&gt;document.writeln(jsvar)&lt;/script&gt;";
   out.println("jspvar"+jspvar);
   session.setAttribute("test",jspvar);
   }
    %&gt;
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now what I am trying is to set the selected value as a session variable.But my bad the value from javascript is not sitting properly on the jsp/java variable and therby my condition <code>if(!(s.equals("Hello")))</code> fails.Can anyone help me here...</p>
  
  <p>Update:</p>
  
  <p>Can the below be the solution for this question</p>
  
  <p>Have a HTML page with two frames. Let the first page contain all the javascript values you wish to populate. The second page(hidden) of the frame actually does the trick. That is actually a JSP. On click of a button (on any action on the first page) in the first page, point your location to the hidden frame (2nd page), perform checks / conversions and populate the variable of the first page using cross frame JAVASCRIPT.</p>