GenuineSounds Posted May 27, 2010 Share Posted May 27, 2010 I want to be able to use the values of the selected number in the drop down list to append into a url. http://genuinesounds.mine.nu/index.php <?php function dropdown( $name, array $options, $selected=null ) { /*** begin the select ***/ $dropdown = '<select name="'.$name.'" id="'.$name.'">'."\n"; $selected = $selected; /*** loop over the options ***/ foreach( $options as $key=>$option ) { /*** assign a selected value ***/ $select = $selected==$key ? ' selected' : null; /*** add each option to the dropdown ***/ $dropdown .= '<option value="'.$key.'"'.$select.'>'.$option.'</option>'."\n"; } /*** close the select ***/ $dropdown .= '</select>'."\n"; /*** and return the completed dropdown ***/ return $dropdown; } ?> <center> <font size=9><b> Refresh interval in seconds. </b></font> <form> <?php $name = 'time'; $options = array( '5', '10', '30', '60', '120' ); $selected = 0; echo dropdown( $name, $options, $selected ); ?> </form> <form method="link" action="getmyip.php?time=<?php print("$NEED THIS PART"); ?>"> <input type="submit" value="Submit"> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/203054-pretty-simple-just-need-a-fix/ Share on other sites More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 Have you tried using a post or get request to the page itself? Basically <?PHP if isset($_GET[$name]) { $time = $_GET[$name]; //some code here to do whatever you want to do with the time variable } ?> If you were to put that before the HTML on the page you would be able to use the header() function to call a newly structured URL. For example: header('Location: http://genuinesounds.mine.nu/getmyip.php?time='.$time); If you don't want to modify headers or it is too difficult for the current use you can always echo a meta refresh tag. echo "<meta http-equiv=\"refresh\" content=\"0;url=http://genuinesounds.mine.nu/getmyip.php?time=".$time."\" />"; Another way may be to use JavaScript, 'document.getElementById['time'].value ' will grab the current selected value. This is the best i gathered of what you are trying to do (refresh the page based on the seconds selected). If that is the case both methods should work. Quote Link to comment https://forums.phpfreaks.com/topic/203054-pretty-simple-just-need-a-fix/#findComment-1064019 Share on other sites More sharing options...
ChemicalBliss Posted May 27, 2010 Share Posted May 27, 2010 You dont need to do this as you already have the options as part of the form (sort of). Instead of having two form tags, you only need one to encapsulate dropdown and the submit button. For example, by default most browsers use the "GET" method for sending form data. (ie, through the URL). So if you have an input/textarea/select or any other form elements in your form, the "NAME" attribute assigned to that element will be used as the "key", whereas the value is self explanatory. Short example: 1. Simple Form <form action="test.php"> <select name="time"> <option value="5">5</option> <option value="10">10</option> <option value="15">15</option> </select> <input type="submit"> </form> 2. What the browser does. Send data via the URL (As no Method was specified in the form tag, defaults to GET). URL = ./test.php?time=(value selected) Where (value selected) is the value that was selected in the dropdown at time of submission. 3. How to act on the data. <?php // Use $_GET for URL Query Items: $user_time = $_GET['time']; // If you set your "Method" in the Form tag to "POST", it will send the data silently (not via the URL, via the HEADERS instead): $user_time = $_POST['time']; ?> -cb- Quote Link to comment https://forums.phpfreaks.com/topic/203054-pretty-simple-just-need-a-fix/#findComment-1064020 Share on other sites More sharing options...
The Eagle Posted May 27, 2010 Share Posted May 27, 2010 Along with what ChemicalBliss has above, <form action="test.php"> <select name="time"> <option value="5">5</option> <option value="10">10</option> <option value="15">15</option> </select> <input type="submit"> </form> Then I guess you can use PHP to grab that data retrieved from the dropdown box, $int = $_REQUEST['time']; header("http://genuinesounds.mine.nu/getmyip.php?time="\.$int."\'"> Although I am second-guessing the above, you can also do it differently. Quote Link to comment https://forums.phpfreaks.com/topic/203054-pretty-simple-just-need-a-fix/#findComment-1064158 Share on other sites More sharing options...
GenuineSounds Posted May 27, 2010 Author Share Posted May 27, 2010 Thank you guys SOOOO much I was WAY over doing the code lol Quote Link to comment https://forums.phpfreaks.com/topic/203054-pretty-simple-just-need-a-fix/#findComment-1064310 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.