inter Posted January 21, 2008 Share Posted January 21, 2008 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! Quote Link to comment Share on other sites More sharing options...
nogray Posted January 21, 2008 Share Posted January 21, 2008 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; Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 21, 2008 Share Posted January 21, 2008 <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> Quote Link to comment Share on other sites More sharing options...
inter Posted January 21, 2008 Author Share Posted January 21, 2008 Thank you both for the quick reply! I appreciate it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.