Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    merge 3 fields into 1

    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">
    <tr>
    <td width="18%"><b>year</b> </td>
    <td width="18%"><b>month</b></td>
    <td width="18%"><b>day</b></td>
    </tr>
    <tr>
    <td width="18%">
    <select name='year' class='form'>
    <option value=""></option>
    <option value="2003">2003</option>
    <option value="2004">2004</option>
    </select>
    </td>
    <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>
    </select>
    </td>
    <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>

    </select>
    </td>
    </tr>
    </table>

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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Hi,

    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;
    alert(y)
    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;
    alert(formObj.joinedDate.value)
    }


    //-->
    </script>
    </head>
    <body>
    <form name='input' action='insert_write.php' method='POST' onsubmit='doit(this)'>

    Vinny
    Where the world once stood
    the blades of grass
    cut me still

  • #4
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi guys,
    thank for replyes..
    would be nice if you Beetle can suggest the php solution..
    also thank Vincent 4 jscript

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $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
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •