Jump to content

Howto concatenate <select> values and save in a single variable?


daniish

Recommended Posts

Hello,

I have the following date selector in an html form:

[code]
<form name=add_blog action="insert.php" method="post">

Title: <br><input type="text" size="79" id="title" method="post" name="title"></input> <br><br>

Date: <br>
<select id="daydropdown"></select>
<select id="monthdropdown"></select>
<select id="yeardropdown"></select> <br><br>
[/code]

How do i concatenate the DATE values and save them in a variable that i can assign to a field in my SQL database?


Many thanks for your help
Use this as the html for your drop down menus
[code]<select id="dropdown['day']"></select>
<select id="dropdown['month']"></select>
<select id="dropdown['year']"></select>[/code]

Then you can access the day, month and year in a single variable called ($_POSt['dropdown'], which will hold an array of the three drop downs.
To access the day you can use $_POST['dropdown']['day'], for the the month you use $_POST['dropdown']['month'] and $_POST['dropdown'][year'] to get the year.

When you want to add them into the database, you can use implode function. Eg:
[code=php:0]$date = implode("-", $_POST['dropdown'];[/code]

What this will do is produce something like this: day-month-year

Does that help?


Hmm i like arrays:)

do you think i can get your method to work with the javascript i am using:
[url=http://www.javascriptkit.com/script/script2/curdateform2.shtml]http://www.javascriptkit.com/script/script2/curdateform2.shtml[/url]

Cheers!
  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.