CcXD Posted March 28, 2008 Share Posted March 28, 2008 Howdy yall! Ok so this is whats happening: I have a Drop down box, in which i have several options (Documet, Sketch, etc). What im doing right now is reloading the page whenever the user clicks on the submit button, and when the page reloads, show a table with all the info. The code is working and all, but i would like it so that everytime the drop down box changes, the table fills itself. For this i guess a more direct way to put it: -How to detect when a dropdown box changes, and alter contents in the website (like populating a text field) accordingly. Here's my WORKING code. <?php //load this part at the beginning if ($action==""){ echo "<b>Edit Project Document Record</b></p>\r\n"; // Select project document types (excluding "ALL") for the dropdown // Form Start echo "<form action=\"EditProjDoc.php\" method=\"post\">\r\n"; echo "<table border=\"0\" cellpadding=\"5\" width=$dblcol12_w>\r\n"; // Create drop-down menu of document types echo "<tr><td width=$dblcol1_w><p>Select Document Type:</td>\r\n"; // Doc Types Drop Down // Hidden Action Var echo "<p><input type=\"hidden\" name=\"action\" value=\"SELECTDOCS\"></p>\r\n"; // Submit Button echo "<tr><td></td><td><p><input type=\"submit\" name=\"submit\" value=\"Submit\"></p></td></tr></table>\r\n"; echo "</form></p>\r\n"; echo "<hr>"; ret_mpc_lnk(); //if user already pressed submit button, load this part instead. } elseif ($action == "SELECTDOCS") { // POST variables $doc_type = $_POST['doc_type']; $project = $_SESSION['project']; if { //form start // Create list menu of project names echo "<form action=\"EditProjDoc.php\" method=\"post\">\r\n"; echo "<table border=\"0\" cellpadding=\"5\" width=800><tr><td width=250 valign=top><b>Select Document(s) to Edit/Delete:</b></br>\r\n"; // Display List //hidden action echo "<p><input type=\"hidden\" name=\"action\" value=\"EDITDOCS\"></p>\r\n"; // Submit Button echo "<tr><td></td><td><p><input type=\"submit\" name=\"submit\" value=\"Submit\"> </p></td></tr></table>\r\n"; echo "</form>"; } } echo "<hr>"; /////////////////////////////////////////// // after selecting the document to be edited, reload this section instead// /////////////////////////////////////////// } elseif ($action == "EDITDOCS") { $doc_index_array = $_POST['doc_index']; $num_docs = count($doc_index_array); if ($number == 0) { echo "<b>No Records Found</b></b>\r\n"; } else { echo "<b>Edit/Delete Project Document(s) - Enter Changes or Select \"Delete Record\" to Delete</b></p>\r\n"; echo "<form action=\"EditProjDoc.php\" method=\"post\">\r\n"; echo "<table border=\"0\" cellpadding=\"5\" width=600>\r\n"; /////////////////////////////////////////// // MAIN FOR LOOP TO LIST ALL DOC SELECTED // /////////////////////////////////////////// ////////////////////////// // END OF MAIN FOR LOOP // ////////////////////////// // hidden vars to pass echo "<p><input type=\"hidden\" name=\"action\" value=\"ADDTODB\"></p>\r\n"; echo "<p><input type=\"hidden\" name=\"num_docs\" value=\"$num_docs\"></p>\r\n"; // Submit Button echo "<table border=\"0\" cellpadding=\"5\" width=600><tr><td width=300></td><td width=300><input type=\"submit\" name=\"submit\" value=\"Submit\"></td></tr></table>\r\n"; } echo "</form>"; echo "</table>\r\n"; echo "<hr>"; } //AFter editing the entries, and clicking on the "add to DB" button, reload only this part } elseif ($action == "ADDTODB") { ////////////////////////// // write data to database loop // ////////////////////////// //return to home page } i really hate loading and reloading the same page over and over again, its anoying and takes time from the browser and user. Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/ Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 i typically use the Javascript onChange action to submit the form. something like <SELECT NAME='option1' onChange='this.form.submit();'> Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503193 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 You want to use javascript and either pull data from an invisible iframe or use AJAX. Plenty of tutorials on google. Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503194 Share on other sites More sharing options...
CcXD Posted March 28, 2008 Author Share Posted March 28, 2008 thanks i guess i need to learn some javascript then.... Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503198 Share on other sites More sharing options...
CcXD Posted March 28, 2008 Author Share Posted March 28, 2008 ok now that i can use onChange function, is the information still sent via POST? Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503264 Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 it submits the form. whatever method the form is using is what will be used. if the form is a POST form, it will post. Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503266 Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 No, unless it is submitted... submitting the page will cause the page to refresh though... Your best bet is to trigger a javascript function on a fake submit button that pulls and parses information from the form and appends it to the url when requesting a php script via AJAX (REMEMBER TO SANITIZE IF REQUIRED). You can then parse the _GET variables as if it had been a form posted Link to comment https://forums.phpfreaks.com/topic/98333-dynamically-change-display/#findComment-503267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.