Using form element in java script using JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhishekbrave
    New Member
    • Dec 2007
    • 79

    Using form element in java script using JSP

    I have following code having a drop down box of months. I want to execute a javascript
    Code:
    onChange
    on the drop down box.
    The javascript funciton is executing a JSP command for seeting session attribute...but i am having problem in taking the value of dropdownbox in javascript please help
    Code:
    function loadsessionmonth()
    {
    <% session.setAttribute("Month",document.cal.month.value);%>
    
    }
    <form name=cal action="calendar.jsp" method=get target=show align=right>
    
    <select name=month onChange="loadsessionmonth()">
    <option value=01>JAN</option>
    <option value=02>FEB</option>
    <option value=03>MAR</option>
    <option value=04>APR</option>
    <option value=05>MAY</option>	
    <option value=06>JUN</option>
    <option value=07>JUL</option>
    <option value=08>AUG</option>
    <option value=09>SEP</option>
    <option value=10>OCT</option>
    <option value=11>NOV</option>
    <option value=12>DEC</option>
    </select>
    <input type=submit value=view >
    </form> 
    </body>
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    JavaScript and JSP don't run on the same processor.
    I mean, JavaScript runs on client side, while JSP is server side scripting.

    The if statements of JavaScript can't lay a condition for JSP.
    Have a look at view source for your page, you may come to know why is is not working.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Absolutely! To solve this, either cause a page reload onchange which sets the session variable or use Ajax.

      Comment

      Working...