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
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;

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.