Save data from multiple selection
I need to Help of using multiple selections of possible options.
Let's say, have 7 options in "Lofc", and need to select some of them, as user wants. User can select, for example, 3 options from 7 possible options using CTRL+mouse. When form is submited in database I found only one of those 3 options, the first one is selected and saved. When I use alert(), it shows exactly what I selected and should be all 3 options in one field of table.
(ie. NESDIS, NMFS, NOS) I cannot find a way to resolve this issue.
I have sample codes and please help !!!
==========================================================
HTML File
==========================================================
<script LANGUAGE="JavaScript">
</script>
International Agreement Database
Leading Office(s) (Select all that apply)
NESDIS
NMFS
NOS
NOAA HQ
NWS
OAR
OTHER
==========================================================
SQL File
==========================================================
CREATE OR REPLACE PACKAGE iad_pkg IS
PROCEDURE insert_rec(
LeadOfc IN varchar2);
END iad_pkg;
/
SHOW ERRORS
CREATE OR REPLACE PACKAGE BODY iad_pkg IS
PROCEDURE insert_rec(
LeadOfc IN varchar2) IS
BEGIN
htp.htmlOpen;
htp.headOpen;
htp.title('International Agreement Database');
htp.headClose;
htp.bodyOpen;
BEGIN
INSERT INTO int_agreement
VALUES(LeadOfc);
COMMIT;
htp.print('The record has been inserted to the table.');
EXCEPTION
WHEN OTHERS THEN
htp.print('Unable to insert record caused by one or more
missing mandatory fields.'||htf.br||sqlerrm);
END;
htp.print('');
htp.bodyClose;
htp.htmlClose;
END insert_rec;
END iad_pkg;
/
SHOW ERROR
Suzanne posted this at 21:53 — 26th April 2004.
She has: 5,507 posts
Joined: Feb 2000
Your input should be an array. I'm not sure with the language you're using what that format is, but in PHP it would be name="lo[]" instead of name="lo", telling the scripting to collect all the options that are selected into an array instead of just a variable.
Oyuni03 posted this at 11:31 — 27th April 2004.
They have: 4 posts
Joined: Apr 2004
I am using html and javascript.
Suzanne posted this at 12:52 — 27th April 2004.
She has: 5,507 posts
Joined: Feb 2000
JavaScript cannot write to a database.
Oyuni03 posted this at 16:32 — 27th April 2004.
They have: 4 posts
Joined: Apr 2004
For HTML FORM ACTION="/fima/owa/iad_pkg.insert.rec
CREATE OR EPLACE PACKAGE iad_pkg IS
PROCEDURE insert_rec(
LeadOfc IN varchar2);
END iad_pkg;
/
SHOW ERRORS
CREATE OR REPLACE PACKAGE BODY iad_pkg IS
PROCEDURE insert_rec(
LeadOfc IN varchar2) IS
BEGIN
htp.htmlOpen;
htp.headOpen;
htp.title('International Agreement Database');
htp.headClose;
htp.bodyOpen;
BEGIN
INSERT INTO int_agreement
VALUES(LeadOfc);
COMMIT;
htp.print('The record has been inserted to the table.');
EXCEPTION
WHEN OTHERS THEN
htp.print('Unable to insert record caused by one or more
missing mandatory fields.'||htf.br||sqlerrm);
END;
htp.print('');
htp.bodyClose;
htp.htmlClose;
END insert_rec;
END iad_pkg;
/
SHOW ERROR
Suzanne posted this at 18:10 — 27th April 2004.
She has: 5,507 posts
Joined: Feb 2000
Hi,
So, just SQL? No database, no server-side language?
http://hobbes.ncsa.uiuc.edu/phpdocs/faq.html.html#AEN63666 if you scroll down just a bit, you can see that in PHP (server-side language), you would name the variable differently for one value, than for an array of values.
What database (Oracle? MySQL? MS SQL? SQL Server? et cetera) are you using and what server-side language are you using? (Java, PHP, Perl, .NET, ASP)?
Suzanne posted this at 18:14 — 27th April 2004.
She has: 5,507 posts
Joined: Feb 2000
Seems like Oracle, btw.
http://db.lib.vt.edu/ows-adoc/psqlwtlk.htm
Perhaps in there will be information on reading select forms. I can see how to create them, but not how to read them.
Oyuni03 posted this at 19:15 — 27th April 2004.
They have: 4 posts
Joined: Apr 2004
Hi,,
Thnaks for your kind reply. I use an Oracle database and procedures in the PL/SQL packages that make up the Web Application Server. As I said earlier, when form is submited in database I found only one of those selected options, the first one is saved in the database. I learned multiple selections options are selected, they are returned as an array: like lo(0), lo(1), lo(2), etc But I want lo(0, 1, 2, ...) in one field of table. I've been working this for almost 2 weeks and still do not know how to figure out.
Need help!
Thanks.
Suzanne posted this at 20:32 — 27th April 2004.
She has: 5,507 posts
Joined: Feb 2000
Are you able to manipulate the data before it is entered into the database?
i.e. are you using a server-side language at all? I'm not familiar with the Oracle db and I'm trying to understand enough to help you out. Being frustrated for weeks on end is no good!
Essentially, if there was no mechanism (such as forcing an array with name="var[]" in the ), then I would take my options and loop through them pushing them into a string that I would store in my db.
However, if there is the ability for the database to be relational in its design, I wouldn't want them to be pushed together in a string, but rather each a row in a lookup table with whatever other table they are associated with.
I don't know how to explain this for Oracle, but perhaps one of those options is within your ability to implement?
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.