Xeon-YK Posted March 26, 2006 Share Posted March 26, 2006 Hi, I'm Beggining in PHP.I Want to ask how to get select value before i submithere is the code i want get and print out the <select name = "education"> value (in line 3) before i click the submit button so when the page load it will print out selected value in this case Jr.HighPlease help me.... thank you01<?php02$education = $_POST["education"];03echo $education; 0i4f (!isset($_POST['submit']))05{06?>070809<form method="post" action="<?php echo $PHP_SELF;?>">10 <select name="education">11 <option value="Jr.High">Jr.High</option>12 <option value="HighSchool">HighSchool</option>13 <option value="College">College</option>14 </select>:<br />15 <input type="submit" value="submit" name="submit"><br />16</form><br />1718<?1920}21else {2223echo $education;24}25?> Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/ Share on other sites More sharing options...
wildteen88 Posted March 26, 2006 Share Posted March 26, 2006 IF you want to show the current selection of the select box before submitting the form it. Then you'll want to look into Javascript to get the current selected value fo the selectbox.Something like this:[code]<?phpif (!isset($_POST['submit'])){?><script type="text/javascript">function getEdu(eduValue){ //alert('Form has changed: value = ' + eduValue); eduText.innerHTML = "You have selected: " + eduValue;}</script><div id="eduText">Make a selection below:</div><br /><form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onChange="getEdu(document.getElementById('edu').value)"> <select name="education" id="edu"> <option value="Jr.High">Jr.High</option> <option value="HighSchool">HighSchool</option> <option value="College">College</option> </select>:<br /> <input type="submit" value="submit" name="submit"><br /></form><br /><?}else{ echo $_POST['education'];}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/#findComment-20886 Share on other sites More sharing options...
Xeon-YK Posted March 27, 2006 Author Share Posted March 27, 2006 thank for reply my question...but i want ask one question again, how i get the select value before submit and i want store to php variabel???thank you Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/#findComment-21097 Share on other sites More sharing options...
wildteen88 Posted March 27, 2006 Share Posted March 27, 2006 You cant do that you will [b]HAVE[/b] to submit the form in order for PHP to create the $_POST['education'] variable this will then hold value fo the option that was selected upon submit. PHP will create this variable automatically.Why do want PHP to create the variable before you submit the form?, as this is impossible to do Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/#findComment-21132 Share on other sites More sharing options...
Xeon-YK Posted March 27, 2006 Author Share Posted March 27, 2006 i want to get the select value because from the selected value i want to use the value in mysql_query and view the result before i submit the formexample :$edu = $_POST["education"];select * from master_education where level=$educan't you help me to solve this problem or you can tell me another solution, thank you... Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/#findComment-21227 Share on other sites More sharing options...
wildteen88 Posted March 27, 2006 Share Posted March 27, 2006 Well in that case you will want to look in to AJAX and PHP for what you want to do. As you can't do what you want to do with just PHP on its own. Have a look at the [a href=\"http://www.ajaxfreaks.com/tutorials/1/0.php\" target=\"_blank\"]AJAX Tutorial[/a] over at ajaxfreaks.com.NOTE: You can get help over at ajaxfreaks.com on the AJAX forum no need to signup again to that forum over at ajaxfreaks.com as your account which you use here should work over there as both forums are tied to the same database. Quote Link to comment https://forums.phpfreaks.com/topic/5860-get-and-print-value/#findComment-21233 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.