Forum Moderators: coopster

Message Too Old, No Replies

Javascript and PHP

Javascript and PHP

         

smurugan

3:31 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



Hello all:

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...?

ergophobe

7:33 pm on Aug 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have this to the point yet that it is submitting a form? In other words, do you know how to send the values in the listboxes to the server and just need to know how to get that data into the DB, or are you having trouble sending the values to the server?

rynaard

4:36 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



i have a similar propblem the difference is that i use a drop down list in an html form to effect the state of various other elements in the same form such as radio buttons and check boxes etc... the thing is when i select an option from the drop down list i want it to automatically update the other components using variables that have been retrieved from a sql dataset. i could post this problem separatly but i feel if someone replies to smurugan's question mine will be answered at the same time ...thanx in advance

ergophobe

7:24 pm on Aug 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Rynaard,

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.

smurugan

2:39 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



Hello ergophobe:

I am still at the stage where I am only able to select items at random, but not able to Submit, which should create variables that will hold all the values, which in turn should eventually be used to populate the database.

ergophobe

3:26 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to specify an action for your form (the address of the script that will handle the form submission) and then a means to submit the form. The easiest is a

<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

smurugan

3:38 pm on Aug 13, 2005 (gmt 0)

10+ Year Member



Hi ergophobe:

<snip>And this is where I got stuck, not knowing how to get the selected values (plural) to be passed on for inserting into a MySql database...

<snip>

[edited by: ergophobe at 4:53 pm (utc) on Aug. 13, 2005]
[edit reason] Please read forum charter regarding code dumps [/edit]

ergophobe

5:00 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Anything in an <input> tag or similar (select, textarea) will be available on the next page, after submission, in the $_POST array.

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.