View Full Version : merge 3 fields into 1

11-10-2003, 09:58 PM
hello, I need to have the field joined automatically filled with data from the 3 select box.
joined field must output date like 2000/02/30 that will be the value inserted in db. If month and day are not selected output should be 00.
thanks in advance for your help

<form name='input' action='insert_write.php' method='POST' >
<table width="400" border="0">
<td width="18%"><b>year</b> </td>
<td width="18%"><b>month</b></td>
<td width="18%"><b>day</b></td>
<td width="18%">
<select name='year' class='form'>
<option value=""></option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<td width="18%">
<select name='month' class='form'>
<option value=""></option>
<option value="01">january</option>
<option value="02">Feb</option>
<option value="03">March</option>
<td width="18%">
<select name='day' class='form'>
<option value=""></option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>


<p> joined date
<input type="text" name="joined">
<INPUT type="submit" class="submit" value="insert" >

11-10-2003, 10:29 PM
Let the PHP do this.

If you *must* have a JS solution, I'll show you, but you really, really, should have the PHP page do this combining.

Vincent Puglia
11-10-2003, 10:58 PM

Since Beetle usually doesn't push serverside solutions, he must have a good reason for asking you to let php do it. So, while you look over this, ask him to help with the php solution.

function doit(formObj)
y = formObj.year.options[formObj.year.selectedIndex].value;
m =formObj.month.options[formObj.month.selectedIndex].index;
if (m < 10) m = '0' + m;
d =formObj.day.options[formObj.day.selectedIndex].index;
if (d < 10) d = '0' + d;
formObj.joinedDate.value = y + "/" + m + '/' + d;

<form name='input' action='insert_write.php' method='POST' onsubmit='doit(this)'>


11-11-2003, 01:52 PM
hi guys,
thank for replyes..
would be nice if you Beetle can suggest the php solution..
also thank Vincent 4 jscript

11-11-2003, 07:19 PM
$date = strtotime( $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day'] );

Then insert $date into your DB as a timestamp.

Reference: http://us4.php.net/manual/en/function.strtotime.php

11-14-2003, 10:17 PM
I used this exact thing once. Here is the snipet I used to get it to work. It's the same but different (shorter code)

<INPUT type="submit" class="submit" value="insert" onMouseOver="input.joined.value=input.year.value + '/' + input.month.value + '/' + input.day.value">

Just a mouseOver right in the button. The only difference is I made the 'joined' text field a hidden field.:)