Populate form values based on previous same form fields

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Populate form values based on previous same form fields

    This message is cross posted in
    alt.comp.lang.php & comp.lang.javascript

    I have a form for a user to input an establishment's hours and what time an
    event is taking place. After the user inputs their establishment's hours of
    operation I want the form elements lower in the form to adjust so that an
    event can only happen when the place is open.

    I have two fields for the hours:
    These are both select fields with values between 0-23
    store_open
    store_close

    Later in the form I have
    event_start
    event_stop

    These values need to be between whatever store_open and store_close are.

    I am stuck.

    Thank you.




    Rizyak Guest

  2. Similar Questions and Discussions

    1. Populate form fields with Unicode data using FDF Toolkit
      Does anyone know about populating PDF Form dynamically with Unicode (read Arabic) data?! It displays English data correctly but displays jumbled data...
    2. Populate Flash Based Form from a cfgrid.
      Hello, I have a flash based form in CFMX 8. It has a two cfinput fields (first name, last name), I also have a cfgrid which displays a list of...
    3. How to access values of form fields on am action page?
      I am sending few form fields to the action page. Here is what it receives (from CF debugging info): Form Fields: 58707001=TBD 587627_01=TBD...
    4. authenticate win32 form client with form based authentication web services
      (Type your message here) -------------------------------- From: kitchai yong Hi, Can you tell me how i authenticate the win32 form client...
    5. How to populate the form fields from another drop down list
      Hello, I would like to populate form fields from one drop down list in the same page. The drop down list's value is from SQL database. When...
  3. #2

    Default Re: Populate form values based on previous same form fields

    Rizyak wrote
    >
    > I have two fields for the hours:
    > These are both select fields with values between 0-23
    > store_open
    > store_close
    >
    > Later in the form I have
    > event_start
    > event_stop
    >
    > These values need to be between whatever store_open and store_close are.
    >
    > I am stuck.
    >
    > Thank you.
    One approach

    Number.protoype.isBetween=function(a,b){
    return this>=Math.min(a,b) && this<=Math.max(a,b);
    }

    if(!( +event_start < +event_end &&
    +event_start.isBetween(+store_open,+store_close) &&
    +event_stop.isBetween(+store_open,+store_close))){
    alert ("NO")
    }
    Mick
    Mick White Guest

  4. #3

    Default Re: Populate form values based on previous same form fields

    "Rizyak" <ryanREMOVEME@latitude47.comANDMETOO> wrote in message news:<ca5jc7$ke4$1@nntp1.u.washington.edu>...
    > I have a form for a user to input an establishment's hours and what time an
    > event is taking place. After the user inputs their establishment's hours of
    > operation I want the form elements lower in the form to adjust so that an
    > event can only happen when the place is open.
    >
    Here is one approach to validating the event times:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Verify time fields</title>

    <script type="text/javascript">

    // ------------------------------------------
    function validateAll()
    {
    alert("in validateAll");

    var x = document.forms["myForm"];
    var inputOK;

    if( x.storeOpen.value == "" )
    {
    alert("Enter a store open time.");
    inputOK= false;
    }
    else if( x.storeClose.value == "" )
    {
    alert("Enter a store close time.");
    inputOK= false;
    }
    else if( x.eventStart.value == "" )
    {
    alert("Enter an event start time.");
    inputOK= false;
    }
    else if( x.eventEnd.value == "" )
    {
    alert("Enter an event stop time.");
    inputOK= false;
    }
    else
    {
    inputOK = checkBoth();
    }

    alert("from validateAll. inputOK = " + inputOK);
    return inputOK;

    }

    // ..............................
    function checkBoth()
    {
    alert("In checkBoth...");

    var x = document.forms["myForm"];

    var inputOK;

    // Convert the times in string format to numeric format
    // in minutes.
    var storeOpen = convertTime(x.storeOpen.value);
    var storeClose = convertTime(x.storeClose.value);
    var eventStart = convertTime(x.eventStart.value);
    var eventEnd = convertTime(x.eventEnd.value);

    alert(".storeOpen.value = " + x.storeOpen.value +
    " storeOpen = " + storeOpen +
    "\n .storeClose.value = " + x.storeClose.value +
    " storeClose = " + storeClose +
    "\n .eventStart.value = " + x.eventStart.value +
    " eventStart = " + eventStart +
    "\n .eventEnd.value = " + x.eventEnd.value +
    " eventEnd = " + eventEnd );

    if ( eventStart > eventEnd )
    {
    alert("Event start must be before " +
    "or equal to event end.");
    x.eventStart.focus();
    inputOK = false;
    }
    else if ( !isBetween(eventStart,storeOpen,storeClose) )
    {
    alert("Event start must occur " +
    "when the store is open.");
    x.eventStart.focus();
    inputOK = false;
    }
    else if ( !isBetween(eventEnd,storeOpen,storeClose) )
    {
    alert("Event end must occur " +
    "when the store is open.");
    x.eventEnd.focus();
    inputOK = false;
    }
    else
    {
    inputOK = true;
    }


    return inputOK;
    }

    // .....................................
    function convertTime(timeString)
    {

    //Convert to a minute based value.
    //Input may either be in 24 hour format
    // or am/pm format.
    // Examples 8:00am, 8, 8:12, 14:30, 2:30pm, or 4:30P.M.

    var theTime = parseInt(timeString,10) * 60;

    if ( timeString.indexOf("p") >= 0 ||
    timeString.indexOf("P") >= 0 )
    {
    theTime += 12*60;
    }

    var minutesIndex = timeString.indexOf(":");
    if ( minutesIndex >= 0 )
    {
    var minutes = timeString.substr(minutesIndex+1);
    theTime += parseInt(minutes,10);
    }

    return theTime;
    }

    // ......................................
    function isBetween(test,a,b)
    {
    return test>=a && test<=b;
    }


    </script>
    </head>

    <body>

    <p>Please try out our form.</p>

    <form name="myForm"
    action="http://www.notavalidwebaddress.com"
    method="POST"
    onSubmit="return validateAll();">

    <p>Store start time:<br>
    <input type="text" name="storeOpen" size="20"><br><br>
    Store end time:<br>
    <input type="text" name="storeClose" size="20"><br>
    </p>
    <p>The little event times.</p>
    <p>Event start time:<br>
    <input type="text" name="eventStart" size="40">
    <p>Event end time<br>
    <input type="text" name="eventEnd" size="40">
    </p>

    <p><input type="submit" border="0" value="Submit">
    </form>

    </body>
    </html>

    Robert
    Robert Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139