Jump to content

[SOLVED] Two dropdown lists in a jump menu


inter

Recommended Posts

 

Hi, this is my first go at making my own javascript, and I'm running into some troubles. It seems to much harder than php! This is what I'm trying to do:

 

Two dropdown lists and a "go" button. The drop down lists aren't dynamic, they're just January to December, and 2007 to 2015 (date and year). I would like the user to select a value for each of the dropdown lists (eg if they select January and 2007, the values are "01" and "07"). The user then clicks the "Go" button, and the page is redirected to webpage/page0107.php?user=<?php echo($user); ?> -- note: the "01" month and "07" year make up the link.

 

I think I have been able to assign the variables 'month' and 'year' from each of the dropdown menus, but I dont know how to make the go button take those variables, and then use them to send the user to the required link. Could anyone please give me a hand with that part of the code?

 

My code so far:

 

in header

<script type="text/javascript">
<!--
function jump_to_selection(month,year){
  var month = getElementById(month);
  var year = getElementById(year);
  var fullurl = month + year + ".php?n=<?php echo($name); ?>";
  // here is where I use the variable $fullurl in a statement to redirect?
}
  //-->
</script>

 

in body:

      <form name="form" id="form">
        <select name="monthselect" id="monthselect"
          <option value="01" selected="selected">January</option>
          <option value="02">February</option>
          <option value="12">December</option>
        </select>
        <select name="yearselect" id="yearselect">
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
        </select>
        <input type="button" name="gobutton" id="gobutton" value=" Go " onclick="jump_to_selection('monthselect','yearselect')" />
      </form>

 

 

 

 

Am I even close? lol

 

Thanks for any responses!

Link to comment
https://forums.phpfreaks.com/topic/86984-solved-two-dropdown-lists-in-a-jump-menu/
Share on other sites

You're almost there. Just a couple of changes

 

In javascript, you'll need to access the object value by accessing the value attribute

 

document.getElementById(ID HERE).value

 

finall add the location.href to redirect to your URL (// here is where I use the variable $fullurl in a statement to redirect?)

 

location.href = 'page'+fullurl;

<script type="text/javascript">
<!--
function jump_to_selection(thismonth,thisyear){
  var month = document.getElementById(thismonth).value;
  var year = document.getElementById(thisyear).value;
  var fullurl = "page" + month + year + ".php?n=<?php echo($name); ?>";
  document.location.href = fullurl;
}
  //-->
</script>

      <form name="form" id="form" onsubmit="return false">
        <select name="monthselect" id="monthselect">
          <option value="01" selected="selected">January</option>
          <option value="02">February</option>
          <option value="12">December</option>
        </select>
        <select name="yearselect" id="yearselect">
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
        </select>
        <input type="button" name="gobutton" id="gobutton" value=" Go " onclick="jump_to_selection('monthselect','yearselect')" />
      </form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.