Thundarfoot Posted February 4, 2008 Share Posted February 4, 2008 here is what I have(which obviously does not work lol) <form id="form1" name="form1" method="post" action=""> <label>Files <select name="select"> <option value="http://localhost/file1.php">File 1</option> <option value="http://localhost/file2.php">File 2</option> </select> </label> <input type="submit" name="submit" value="submit"> Basically I think my option value is wrong... any help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/ Share on other sites More sharing options...
pdkv2 Posted February 4, 2008 Share Posted February 4, 2008 What you expect from the above code please be specific. Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457438 Share on other sites More sharing options...
Thundarfoot Posted February 4, 2008 Author Share Posted February 4, 2008 I want to select option 1 or 2 from the drop down list, click submit, and have file1.php or file2.php load in the current brrowser window. thank you for your time Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457441 Share on other sites More sharing options...
pdkv2 Posted February 4, 2008 Share Posted February 4, 2008 You need to submit the form using javscript <script language="javascript"> function submits(form1){ val=form1.sel.value form1.action = val; form1.submit(); } </script> call the above funcion on click of the submit button and change the buttons inpu type to button from type=submit Rgds Sharad Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457443 Share on other sites More sharing options...
thebadbad Posted February 4, 2008 Share Posted February 4, 2008 Using PHP you could put this in top of the file with the form: <?php if (isset($_POST['select'])) { $redirectTo = $_POST['select']; header("Location: $redirectTo"); exit; } ?> // form down here somewhere Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457459 Share on other sites More sharing options...
pdkv2 Posted February 4, 2008 Share Posted February 4, 2008 What if one need to keep the first option selected by default Cheers ! Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457469 Share on other sites More sharing options...
Thundarfoot Posted February 4, 2008 Author Share Posted February 4, 2008 thank you for the php example works like a charm. I simply made the first option read Choose file and left its value blank..again thanks for the help to both of you. Quote Link to comment https://forums.phpfreaks.com/topic/89331-solved-drop-down-form-option-syntax/#findComment-457474 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.