sigkill-9 Posted March 2, 2009 Share Posted March 2, 2009 I made a php form that allows the user to select movies from a fairly standard html select menu, but currently you need to select a movie from the drop down list, then hit the submit button before the movie details will be populated to the page. What I'd like to have happen is this: As soon as the user selects a movie from the drop down list, the movie details are populated to the page, without the need to hit a submit button. It seems like it's a real simple proceedure, but for some reason I cant figure it out... Here's the foreach code that populates the list with movie info: echo '<div class="container">'; echo '<div>Select a Movie:</div>'; echo '<form method="post" action=?>'; echo '<input type="hidden" name="id" value="' . $id . '" >'; echo '<select class="input" name="id">'; foreach($title_array as $value) { $id = $value['id']; $title = $value['title']; $t = '<option value="' . $id . '"'; if ($value['id'] === $_POST['id']) $t .= ' SELECTED'; echo $t . '>'. $title . '</option>\n'; } echo '</select><input type="submit" value="Submit"></form></div>'; echo '</div>'; Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/147519-solved-noob-need-help-updating-page-instantly-when-drop-down-menu-item-selected/ Share on other sites More sharing options...
RussellReal Posted March 2, 2009 Share Posted March 2, 2009 echo '<div class="container">'; echo '<div>Select a Movie:</div>'; echo '<form method="post" action=?>'; echo '<input type="hidden" name="id" value="' . $id . '" >'; echo '<select onchange="this.parent.submit()" class="input" name="id">'; foreach($title_array as $value) { $id = $value['id']; $title = $value['title']; $t = '<option value="' . $id . '"'; if ($value['id'] === $_POST['id']) $t .= ' SELECTED'; echo $t . '>'. $title . '</option>\n'; } echo '</select><input type="submit" value="Submit"></form></div>'; echo '</div>'; Link to comment https://forums.phpfreaks.com/topic/147519-solved-noob-need-help-updating-page-instantly-when-drop-down-menu-item-selected/#findComment-774395 Share on other sites More sharing options...
sigkill-9 Posted March 2, 2009 Author Share Posted March 2, 2009 Thanks Russel for your help. I copied/pasted your code example but it didnt work. I found out why though. After some research on the options for the select menu "onchange" attribute (which I didnt know existed...) I found an example showing this: <select name="select" class="tabletxt" onChange="document.form1.submit()"> I adapted it to fit my code by adding name="form1" to the form tag, and and tried it but had a problem. The only thing that was displaying on the page was the select menu. All the movie details (which normally appear below the select menu) were simply not there... When I selected from the drop down, the page refreshed so I could tell that it was functioning properly so I dove into the code again and after some expirementing I found what was causing the movie details to not be displayed. It was the submit button/code. For some reason with the submit button visible, the movie details were invisible. I commented out the submit button but that didnt work, so I changed the submit buttons type from "submit" to "hidden" and viola! It works like a charm. Just FYI for anyone else that may have the same issue... I had no idea it wasnt a PHP issue, so sorry for that, but thanks for the help and thanks for helping me learn.[/code] Link to comment https://forums.phpfreaks.com/topic/147519-solved-noob-need-help-updating-page-instantly-when-drop-down-menu-item-selected/#findComment-774443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.