0

I have the following field in a jsp page..

   <select size="1" name="typ">
                                    <option value="C">Coffe</option>
                                    <option value="T">Tea</option>
                                    &nbsp;
                                </select>

Now when the user selects Coffeand and clicks submit, I want the page to go to Coffe.jsp
and when Tea is selected , i want it to go to Tea.jsp

I tried using the following jquery code but it is not working...

 jQuery(document).ready(function() {
                jQuery("#typ").change(function() {
                    if(this.options[this.selectedIndex].value == "C") {
                        window.location = "/Coffee.jsp";
                    }
                });

I am a newbie in jquery script and jsp...

4
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by trhtrh
0

You can call javascript method on onchange() event of select and you can work on your logic to redirect.Something like this:-

javascript method

function redirect_url(url )
{
  alert(url);
}

select tag

 <select size="1" name="typ" onchange="redirect_url(this.value)">
                                    <option value="C">Coffe</option>
                                    <option value="T">Tea</option>
                                    &nbsp;
                                </select>
0

you just have to use javascript for that as

<script type="text/javascript">
        $(function(){
           $('id').bind('change', function () {
             var url = $(this).val(); // get selected value
             alert(url); // This will help to check whether JS is getting executed.
             if (url) { // require a URL
                window.location = url; // redirect
             }
             return false;
           });
       });
</script>

you have to give id as you have given in the select tag.add this js file to your project.
else

you can write one more function i.e. on change event

function useme() {
  url=document.entry.Country.value
  if (url=="UK")
  {
  /*here i want to call the page response.jsp */
 alert('complete');
document.entry.action="response.jsp";
document.entry.subnit();

  }
  else

      {
      /*here i want to call the page submit.jsp */
         alert('now')
      }
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.