shahzad429 Posted December 19, 2012 Share Posted December 19, 2012 I have use this This to make add/remove select list <form action="home.php?action=test" method="post" id="myform" name="myform" onsubmit="ValidatePageForm()"> <fieldset> <select name="selectfrom" id="select-from" multiple size="5"> <option value="1">Item 1</option> <option value="2">Item 2</option> <option value="3">Item 3</option> <option value="4">Item 4</option> </select> <a href="Javascript:void(0);" id="btn-add">Add »</a> <a href="Javascript:void(0);" id="btn-remove">« Remove</a> <select name="selectto" id="select-to" multiple size="5"> <option value="5">Item 5</option> <option value="6">Item 6</option> <option value="7">Item 7</option> </select> </fieldset> <input name="submit" type="submit" value="submit" /> </form> using below script i can see values of selected options <script type="text/javascript"> function ValidatePageForm() { $('#select-to option').each(function(){ alert($(this).val()); }); } </script> But how can i take these values and store them in database?? because when i submit i dont get see data in post dump. any help regarding this please. Thanks, Shahzad Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/ Share on other sites More sharing options...
Muddy_Funster Posted December 19, 2012 Share Posted December 19, 2012 Are you femilliar with the difference between javascript and PHP? Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400257 Share on other sites More sharing options...
shahzad429 Posted December 19, 2012 Author Share Posted December 19, 2012 I know but no help from javascript section so i thought maybe some one from PHP area know how to take this value and store them in database. thanks is why i post this here. Sorry Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400262 Share on other sites More sharing options...
codefossa Posted December 19, 2012 Share Posted December 19, 2012 So, your question is about storing them in the db? Or is it getting the data to a PHP page to be dealt with? If it's the first, are you trying to do it without having to refresh the page, or give a custom action after posting the form? Otherwise this would be purely a PHP question, but I'll help anyways just please clarify it. If you are just posting it, then the HTML form would take care of it for you. If you want JS to handle the form, $.serialize() then send the data. If you are having trouble getting the data because you're selecting parts to send from the form you have, then you could make hidden fields to have sent and deal with them like any other form item once sent to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400365 Share on other sites More sharing options...
shahzad429 Posted December 19, 2012 Author Share Posted December 19, 2012 the goal is what ever user select to store those options in DB for later retrieval. so what ever method is good tell me. right now in front end user can add and remove option but what i want when he submit i should know when he select so that i can save them. Thanks, shahzad Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400368 Share on other sites More sharing options...
codefossa Posted December 19, 2012 Share Posted December 19, 2012 (edited) Well, since you need JS to use the form in the first place, we can just use JS to get it set up because JS-disabled browsers can't use the form to begin with. This isn't good practice, but you can Google about all of that if you care. Create a new form. This will be what we actually submit. var form = $(document.createElement("form")); Now when you select an item, add it to the form. var item = $(document.createElement("input")).attr({ 'name': myName, 'type': "hidden", 'value': myValue }); form.append(item); When you're ready to submit, serialize the form and post it. var postdata = form.serialize(); $.post(myURL, postdata, function(data) { /* success function */ }); Now you just deal with it in PHP like you would any other form. $_POST['myName'] is equal to myValue from our JS. Note that none of this is tested, so if there's a mistype or I got something wrong, sorry. (: Edited December 19, 2012 by Xaotique Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400371 Share on other sites More sharing options...
shahzad429 Posted December 20, 2012 Author Share Posted December 20, 2012 Thank you it worked thank you very much for you help. Quote Link to comment https://forums.phpfreaks.com/topic/272171-store-values-from-add-remove-select-lists/#findComment-1400550 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.