+ Reply to Thread
Results 1 to 9 of 9

Thread: How do I make my HTML form active?

  1. #1
    Steeevoe is offline x10 Sophmore Steeevoe is an unknown quantity at this point
    Join Date
    Feb 2009
    Location
    Leicestershire [UK]
    Posts
    103

    How do I make my HTML form active?

    I am struggling to get a date of birth selection working.

    I have three fields, day, month and year.
    Day and Month are select fields.


    I would like the day field to change according to the month selected with the page refreshing. So I would like 30 days available when month is April, June, July, Sept and Nov, 31 days for the other months apart from February with 28 (apart from leap year)

    I have tried google but I can't find a lead to how I am supposed to sovle this.

    Please help!



    (note I am using php method to submit form when finished)
    The above message was posted by a guy called Steevoe. We hope you enjoyed his comment

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: How do I make my HTML form active?

    this drop down box might be easier:

    http://www.nsftools.com/tips/DatePickerTest.htm
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: How do I make my HTML form active?

    Firstly, set a variable according to month chosen using a series of if, thens.

    PHP Code:
    <?php
    $daysinmonth
    =31;//set default
    if ($_POST['month'] =="Jan"){
    $daysinmonth=31;
    } else if (
    $_POST['month'] == "Feb"){
    $daysinmonth=28;
    }

    etc... etc... for each month
    Then you need your select field for the dates..

    PHP Code:

    <select name="selectdate" id="selectdate">
           <?php
        
    for ($i 1$i <= $daysinmonth$i++)//starting at 1 and looping until daysinmonth is reached - then incrementing by 1
        
    {
        echo 
    '<option value="'$i '" ';// value
        
    echo  ">" $i "</option>";// viewed
        
    }
        
    ?>
          </select>
    Haven't tested this so the sytax might be a bit off, but the principle is OK.

    ______________

    The trouble with this is that you have to refresh - some use AJAX, which could achive this without refreshing, but I don't know enough to help on this.

    Alternatively, as posted above, you could just rip one thats already done!
    Last edited by freecrm; 03-10-2009 at 05:19 PM.

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: How do I make my HTML form active?

    That will work too, the only problem is leap years
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    mattura's Avatar
    mattura is offline x10 Elder mattura is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    563

    Re: How do I make my HTML form active?

    Look up javascript.
    It's not that difficult to learn if you know php and will be able to dynamically change the fields.
    Just give everything an id parameter (<input id='box1' />) and refer to the element by document.getElementById(theID) and use innerHTML
    eg
    HTML Code:
    <select id='datebox'></select>
    <script>
    document.getElementById('datebox').innerHTML="<option>1st</option><option>2nd</option>";
    </script>
    ----
    Life is a game. The conception is terrible but the graphics are amazing!
    matt.elementfx.com

  6. #6
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: How do I make my HTML form active?

    Or you could let the user submit any date, and check on server-side...
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  7. #7
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: How do I make my HTML form active?

    Assuming the user gives you the year and the month, you can also get the number of days like this:

    PHP Code:
    <?php

    //Number of days for the given month and year

    $month "2";
    $year  "2008";

    $days date("t"mktime(000$month1$year));

    // Prints: The year/month 2008/2 has 29 days!
    echo "The year/month  " $year "/" $month " has " $days " days!";

    ?>
    ... and then build your options up to that number of days.

  8. #8
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: How do I make my HTML form active?

    Nice - good contribution!

  9. #9
    Steeevoe is offline x10 Sophmore Steeevoe is an unknown quantity at this point
    Join Date
    Feb 2009
    Location
    Leicestershire [UK]
    Posts
    103

    Re: How do I make my HTML form active?

    Thank you guys. Much apprecited. Just got to find the time to do it. We happen to be decorating at the mo ^^
    The above message was posted by a guy called Steevoe. We hope you enjoyed his comment

+ Reply to Thread

Similar Threads

  1. Make $ 500 USD new business idea....
    By John Klyne in forum Earning Money
    Replies: 4
    Last Post: 11-09-2008, 06:11 PM
  2. Free MMORPG's...
    By FeestBijtje in forum Gamer's Lounge
    Replies: 15
    Last Post: 09-20-2007, 01:51 PM
  3. A simple Visual Basic Login Form
    By Zenax in forum Tutorials
    Replies: 0
    Last Post: 03-13-2007, 08:59 AM
  4. Form Processor, 100-1000 points
    By Tyler in forum The Marketplace
    Replies: 8
    Last Post: 08-19-2006, 08:08 PM
  5. [IPB] Contiguous Board Index
    By phenetic in forum Tutorials
    Replies: 5
    Last Post: 09-18-2005, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers