POST contents of a listbox

Hi! I have a dual listbox thing where the left and right is populated from a database. There's some buttons and a bit of JS that allows items to move left and right between the two. Basically copied this and added my own database logic: https://codepen.io/afrost/pen/EyQOxx My data/schema is pretty simple - id# and a name. What I want to do (ultimately) is insert the id's of the contents of the right listbox to a database. If I can get the id's into a variable/array, I'll be able to go from there. Does that make sense? Test code is below - I've had to trim it because of the 2000char limit but it should have the pertinent bits. I'll add the missing bits below if needed. The left list populates correctly and I can move items left and right as I wish. I want to extract the contents of the rightmost column on a 'submit'. cheers! <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script> the JS from that URL. </script> <form action="/lists.php" method="POST"> <div class="approveTermsContainer"> <div class="newItems"> <b>Available organisations:</b><br/> <select multiple="multiple" id="lstBox1"> <?php foreach ($orgs as $row) { echo '<option value="'.$row["id"].'">'.$row["name"].'</option>'; } ?> </select> </div> <div class="transferBtns"> <input type='button' id='btnRight' value =' > '/> <br/><input type='button' id='btnLeft' value =' < '/> <div class="submitContainer"> <input type="submit" value = "submit"/> </div> </div> <div class="approvedItems"> <b>Selected Organisations: </b><br/> <select multiple="multiple" id="lstBox2" name="AdminOrgs"> </select> </div> </div> </form>
1 Reply
foggy
foggy13mo ago
thanks - i worked it out in the end. Yes, it would work if I selected the things on the right before sending, but thats not what I want. I used some JS to scan the lists then post the contents to a hidden <input> the value of which was submitted on the POST. All works now and my MySQL db is being populated with the contents of the column on the right, which is what I wanted :). Yes absolutely - and it's a great feeling when the bits you've cobbled together finally work! Sometimes it's good just to get a nudge in the right direction though. I'm not always sure what I'm doing is the 'right' way of doing something!