Forum Moderators: coopster
I have a javascript code that displays 2 listboxes say "A" and "B". "A" contains a full complement of items. "B" can be populated with one or more items from "A". Now, I want to get the names of the items that have been selected (from "A" and populated in "B") to be added into a table in MYSQL...
Any ideas...?
The problem for you is that you can only fetch data from your DB by sending another request to the server, which effectively means reloading the page unless you're running some sort of applet. So you're faced with three options as far as I know
- reload the page to get the additional data
- grab all the data on the initial page load and use some client-side scripting to hide/show the data
- have some sort of applet running that can fetch data without reloading the page.
Smurugan has all the data there, the question is whether he needs help with getting the form to submit the data from B, or whether he just needs to know how to handle that data once it's received and get it into the DB.
<input type="submit" name="mySubmit" value="Send This">
You can also do it with Jacascript if need be. An abbreviated version of what I use is
function submitForm(FormID) {
var form = document.getElementById(FormID);
form.submit();
return;
}
FormID is the "id" attribute of the form element
You need to put an "action" in your <form> element that sends the results to some script that will do the processing. That can be the same script that serves the form, or another one. To get you started, let me suggest something like this
-------
page1.php
---------
<form method="post" action="page2.php">
[then other form tags like <input> and what not]
-----------
page2.php
-------------
<pre>
<?php
if (!empty($_POST))
{
print_r($_POST);
}
Once you have the post values showing, the mysql part will be easy.