Morris2 Posted October 28, 2011 Share Posted October 28, 2011 Hello PHP world! I have this roll-down-select-menu working, reflecting a column in my database. I am able to retrieve the selected value after submit, that takes me to another code page. But I would like to use this value on the form page, that contains the roll-down-menu and the submit button. Is there a way to enter the chosen value into this variable $uan, without having to submit the page first? I tried to retrieve the value on this page with the POST lines at the button, but without luck. I think the value is only entered upon submit? Thanks in advance for your clever advice. Best regards Morris <?php $query = "SELECT * FROM Uniq_artist_name" ; $result = mysql_query($query); echo'<select name="uan">'; while($row = mysql_fetch_assoc( $result )) { echo '<option value="'.$row['uniqartistname'].'">'. $row['uniqartistname'] .'</option>'; } echo '</select>'; $uan = $_POST["uan"]; echo "$uan"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/249972-is-there-a-way-to-enter-the-chosen-form-value-without-having-to-submit-first/ Share on other sites More sharing options...
phily245 Posted October 28, 2011 Share Posted October 28, 2011 If you dont mind a page refresh, try adding this code to the select button (replacing my_page.php with your page url): onChange="javascript: window.location = 'my_page.php?uan='+this.value;" and at the top of the page add this: <?php if(isset($_GET["uan"]) &&$_GET["uan"] !='') { $uan = $_GET["uan"]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249972-is-there-a-way-to-enter-the-chosen-form-value-without-having-to-submit-first/#findComment-1282951 Share on other sites More sharing options...
Morris2 Posted October 28, 2011 Author Share Posted October 28, 2011 Thanks for this. I just tried this, debugger says: unexpected T_STRING, expecting ',' or ';' in this line: echo'<select name="uan"onChange="javascript: window.location = full_web_url_to_this_page?uan='+this.value;">'; Can't see whats wrong here. Besides from that, did I undertand this right: full_web_url_to_this_page?uan Is it possible to do this without updating the page? Regards Morris Quote Link to comment https://forums.phpfreaks.com/topic/249972-is-there-a-way-to-enter-the-chosen-form-value-without-having-to-submit-first/#findComment-1282983 Share on other sites More sharing options...
trq Posted October 28, 2011 Share Posted October 28, 2011 To submit data to the server without refreshing the page you would need to use Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/249972-is-there-a-way-to-enter-the-chosen-form-value-without-having-to-submit-first/#findComment-1282986 Share on other sites More sharing options...
phily245 Posted October 28, 2011 Share Posted October 28, 2011 Sorry, that was a mistype. Try using this thread post: http://forums.digitalpoint.com/showthread.php?t=16822 Quote Link to comment https://forums.phpfreaks.com/topic/249972-is-there-a-way-to-enter-the-chosen-form-value-without-having-to-submit-first/#findComment-1283008 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.