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 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    how to add text boxes dynamically

    hi guys i have problem with time sheet.i have 3 shifts.
    1.morning (7 am to 4pm)
    2.afternoon (2 pm to 11 pm)
    3.night (10 pm to 6 am)
    these 3 are radio buttons. when i select one radio button ike morning, below the radio buttons it will dispaly two select lists From and To. And the user should submit hourly reports for every hour.
    The option values in From select list is 7,8,9,10,11,12,13.14,15,16 likewise)and alternatively in To select list have (7,8,.....so on).
    if user select morning shift ,it displays From selct list like 7 and To select list 8.and we provide text box corresponding to select lists for entering description.and i want button right side of text box ,when i click it will automatically add next hour select list From 8 -TO 9 it is also have text box for entering descrption and right side of this have button to add next hour select list .these select lists are added dunamically with one hour time differenece.Please any one help to do this

  • #2
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Umm. Is there a simplier explanation of what you need to do?

  • #3
    Regular Coder 2reikis's Avatar
    Join Date
    Nov 2005
    Location
    California
    Posts
    167
    Thanks
    17
    Thanked 13 Times in 13 Posts

    Here's a try

    This represented such an interesting excercise I thought I'd have a shot at what I thought you meant. If it's not, no harm done. Just ignore this post.

    [CODE<html>
    <head>
    <title>Shift Report</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function fnSetShift(i) {
    f = document.form1
    for (opt = 0; opt <= 7; opt++) {
    f.slcFrom.options[opt].value = (opt+parseInt(i)).toString()
    f.slcFrom.options[opt].text = (opt+parseInt(i)).toString();
    f.slcTo.options[opt].value = (opt+parseInt(i)+1).toString();
    f.slcTo.options[opt].text = (opt+parseInt(i)+1).toString();
    obj = document.getElementById("taList")
    obj.innerHTML = '<textarea name="taShiftStart" cols="80" rows="10"></textarea>
    '
    }
    }
    function addIt() {
    f=document.form1
    obj=document.getElementById("taList");
    obj.innerHTML = '<textarea name="ta' + f.slcFrom.selectedIndex + '" cols="80" rows="10"></textarea>' + obj.innerHTML
    inc(f.slcTo,f.slcFrom)
    }
    function inc() {
    for (i=0; i<arguments.length; i++) {
    obj=arguments[i]
    obj.selectedIndex++
    }
    }
    </script>
    </head>
    <body>
    <form action="#" method="get" name="form1" onSubmit = "return false">

    <table cellspacing="0" cellpadding="0">
    <tr>
    <td>1<sup>st</sup></td>
    <td>2<sup>nd</sup></td>
    <td>3<sup>rd</sup></td>
    </tr>
    <tr>
    <td><input name="rdShift" type="radio" value="7" checked onClick="fnSetShift(this.value)"></td>
    <td><input name="rdShift" type="radio" value="14" onClick="fnSetShift(this.value)"></td>
    <td><input name="rdShift" type="radio" value="22" onClick="fnSetShift(this.value)"></td>
    </tr>
    </table>

    <p>
    From:
    <select name="slcFrom">
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    </select>
    &nbsp;&nbsp;&nbsp;To:
    <select name="slcTo">
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    </select>
    &nbsp;&nbsp;&nbsp;
    <input type="button" name="addEntry" value="Add Entry" onClick='addIt();'>
    </p>
    <p id="taList">
    <textarea name="taShiftStart" cols="80" rows="10"></textarea>
    </p>
    <p>&nbsp;</p>
    </form>

    </body>
    </html>
    [/CODE]

    HTH
    2reikis
    Last edited by 2reikis; 08-31-2007 at 01:11 PM. Reason: added reset for taList in fnSetShift()

  • #4
    Regular Coder
    Join Date
    Feb 2007
    Location
    Seattle
    Posts
    153
    Thanks
    5
    Thanked 9 Times in 9 Posts
    Nice work! I tried it both FF and IE7; in FF I can't get the text field to keep the text when adding a new entry. Any thoughts?

    Gary


  •  

    Posting Permissions

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