harryuk Posted August 1, 2011 Share Posted August 1, 2011 Hi, I would like to use the $_POST function for the sub-category section of the form. The problem i am having is how i can do this as i am using javascript to automatically update the sub-category section when a item is selected in the category section. So where and how would i put the $_POST function so i can echo the form info including what sub-category item i selected out on my index.php page. I hope that makes sense. Please help Thank you team = new Array( new Array( new Array("Toesavers", 39482304), new Array("Dr. Martens Industrial", 34802389), new Array("Himalayan", 39823498), new Array("Caterpillar", 87587343), new Array("Timberland", 68798735) ), new Array( new Array("Hand Protection", 23840238), new Array("Eye & Face Protection", 92390484), new Array("WeatherWear", 29048203), new Array("Head Protection", 94098230), new Array("Hearing Protection", 39234923), new Array("Respiratory Protection", 29345423) ), ); function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) { var i, j; var prompt; // empty existing items for (i = selectCtrl.options.length; i >= 0; i--) { selectCtrl.options[i] = null; } prompt = (itemArray != null) ? goodPrompt : badPrompt; if (prompt == null) { j = 0; } else { selectCtrl.options[0] = new Option(prompt); j = 1; } if (itemArray != null) { // add new items for (i = 0; i < itemArray.length; i++) { selectCtrl.options[j] = new Option(itemArray[i][0]); if (itemArray[i][1] != null) { selectCtrl.options[j].value = itemArray[i][1]; } j++; } selectCtrl.options[0].selected = true; } } <form> <select name="Make" onchange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));"> <option value="-1" selected="selected">Select Category</option> <option value="1">Footwear</option> <option value="2">PPE</option> <option value="3">Ladders</option> </select></label> <label> Sub-Category <select name="Team"> <option></option> <option></option> <option></option> <option></option> <option></option> <option></option> </select></label> </form> Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 Are you planning update the mysql using js? Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 Yes i would need it to update mysql as well as echoing out in to a table. Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 I didn't really read the code but after reading the replies I assume that you wanna use ajax with an external php script to modify the database Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 One problem.....Not familar with AJAX Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 Well then familiarize, it's not that complicated and it's extremely useful ^^ Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 ok Thanks. Updating to mysql i not a priority it is more important to be able to echo the form info out in a different page. Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 well I assume you are aware that in order to use POST you need to have a form submit the data to the other page, with that said you can just auto-update those items before the submit is triggered and then you can access them :? Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 Yes sorry i do have a submit button i didnt copy all of my coding. How would you auto update???? The java script updates it when i have ftp'ed it but i need to be able to show what sub-category item i selected when i have submitted. Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 Well I don't really get what's supposed to happen but I understand you have some catalog or something where users select stuff and when they select something some other stuff is autoupdated and you want this autoupdated stuff to be accessible in another page via post, is that correct? Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 JavaScript that runs on the client-side PHP run on the server side (server-side language) You need AJAX to pass variable between php and js http://www.w3schools.com/PHP/php_ajax_database.asp Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 Yes exactly. Under the sub-category section all the option tags have no values until an item is selected on the category section. Usually you would have values already in the option tag so you can add your $_POST function in order to send all form info to another page. But in this instance i do not have any values to be able to add a $_POST function?!?! Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 ok viop thank you i will have a look. Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 It's not entirely true you need ajax to pass variables, you can set hidden input fields' values via php and then access them with js but it's risky sometimes Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 ok would you mind giving an example??? Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 Sure when you're setting up the page if you have some passed data from another page which you need to access in javascript you can do this <? echo "<input type='hidden' id='someid' value='Received data here'/>"; ?> then you access it in js like so thedata = document.getElementById('someid').value Quote Link to comment Share on other sites More sharing options...
harryuk Posted August 1, 2011 Author Share Posted August 1, 2011 ah that makes sense thank you every much for your time1 Quote Link to comment Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 but I don't really recommend this unless you're using it for some crap because it's really easy for a user to edit those hidden inputs, unless there's some way to protect them I'm not aware of Quote Link to comment 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.