www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Thread: [RESOLVED] Auto change field values after user changes something...?

  1. #1
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264

    resolved [RESOLVED] Auto change field values after user changes something...?

    Ok, so i have a form, and it loops to create a new "set" of data for each of the items in my database list.

    Basically, I have this for each line:

    - Title
    - Duration
    - Start Date
    - Assigned User
    - Completion Status

    I need the start-date to get bumped by "X" amount of days if one of the items changes... so that every line following the one that was changed manually will just automatically update with "X" days later for the starting date.

    So if title1box was the ID for task 1... and title2box was the ID for task 2, and so on... If you change task 4 to start 2 days later than before, I need tasks 5, 6, 7, 8, 9, etc to update to 2 days later but I need tasks 1, 2, and 3 to be left alone.

    Any advice?

  2. #2
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Oh! Also, I'd like for this to happen automatically while they're filling it out so that they can then edit other ones afterward with the right values in them. But I don't want it to save the changes until they click submit. I can handle that part on my own.

  3. #3
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    I really do need some help with this.... ASAP.

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    it's a good idea to show your (maybe simplified) code. if somebody decides to help you he must write "your page" with "your form" to test the script. if you need help respect people who help you )
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  5. #5
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    My code is a mess, so I don't know how helpful that would be.

  6. #6
    Join Date
    Nov 2010
    Posts
    1,055
    push your form fields onto an array, find out the index of the field that was changed, then loop through the fields after that index number, getting the existing value and adding whatever the changed amount was to each field value.

    but Padonak is right... if you want something more specific, it would probably be wise to show some code at least...

  7. #7
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Ok, my page loops through each "type of task" and displays one set of this for each one... Hope it helps.

    Also, the "_1" is the part that increments per task, so the next one would have "_2" then "_3" and so on... for each task.

    HTML Code:
    <tr class="oddTD tableTopRow">
        <td rowspan="2"><input type="checkbox" name="done_1" value="complete" onClick="javascript:return confirm('Warning!\n\nThis change is permanant. If you mark this task complete\nyou will need to ask the system administrator to reset\nthis task if you made a mistake or want it to show again.\n\nAre you sure you want to mark this task as completed?')" /></td>
        <td rowspan="2" class="leaderCol">Task Title</td>
        <td class="datepicker"><input name="start_1" value=""></td>
        <td><select name="person_1"><option style="color:rgb(204,204,204);font-style:italic;">No Person Assigned</option>    	<option value="5">John Smith</option>    	<option value="4" selected>Jane Smith</option>    </select></td>
        <td rowspan="2"><textarea name="notes_1" rows="1"></textarea></td>
    </tr>
    <tr class="oddTD">
        <td class="datepicker"><input type="button" value="Select" onclick="displayDatePicker('Start0Date', this);"></td>
        <td><select name="duration_1">
    		<option value="1">Task takes 1 Day</option>
    		<option value="2">Task takes 2 Days</option>
    		<option value="3" selected>Task takes 3 Days</option>
    		<option value="4">Task takes 4 Days</option>
    		<option value="5">Task takes 5 Days</option>
    		<option value="6">Task takes 6 Days</option>
    		<option value="7">Task takes 7 Days</option></select></td>
    </tr>
    So if the start-date or the duration change for one task then all of the following tasks need up date with the same amount of days added or subtracted from what it was before.

  8. #8
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Ok, so this is what I have at present...

    HTML Code:
    <input type="hidden" name="lot" value="1804" />
    <tr class="oddTD tableTopRow">
        <td rowspan="2"><input type="checkbox" name="done_2" value="complete" onClick="javascript:return confirm('Warning!\n\nThis change is permanant. If you mark this task complete\nyou will need to ask the system administrator to reset\nthis task if you made a mistake or want it to show again.\n\nAre you sure you want to mark this task as completed?')" /></td>
        <td rowspan="3" class="leaderCol">Backfill</td>
        <td class="datepicker"><input name="start_2" value="04/16/2012" class="orOddEven"></td>
        <td><select name="person_2">
        	<option style="color:rgb(204,204,204);font-style:italic;">No Person Assigned</option>
            <option value="6">John Smith</option>
            <option value="5">Jane Doe</option>
            <option value="4">Joe Schmoe</option>
        </select></td>
        <td rowspan="3"><textarea name="notes_2" rows="3"></textarea></td>
    </tr>
    <tr class="oddTD">
        <td class="datepicker"><input type="button" value="Select" onclick="chooseDate('Start0Date', this);"></td>
        <td><select name="duration_2">
    		<option value="1">Same Day</option>
    		<option value="2">Task takes 2 Days</option>
    		<option value="3">Task takes 3 Days</option>
    		<option value="4">Task takes 4 Days</option>
    		<option value="5">Task takes 5 Days</option>
    		<option value="6">Task takes 6 Days</option>
    		<option value="7">Task takes 7 Days</option></select></td>
    </tr>
    
    <tr class="oddTD">
            <td><input type="submit" value="-" class="incbutton"><input type="submit" value="+" class="incbutton"></td>
        <td colspan="2">Last Updated (N/A)</td>
    </tr>
    I have a set like that generated for each task in the database's "list" of tasks...

    I'm still having trouble figuring out how to make each additional task update to a later starting-date.

    Also, I'd like the little "-" and "+" buttons to be the ones to affect that change.

    Any help would, as always, be greatly appreciated.

  9. #9
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Also, I don't need it to save the changes to the server until they're done and they can click submit... I just need it to auto-populate the date field when they click + or - and automatically update every task after it with the same amount added or subtracted.

  10. #10
    Join Date
    Nov 2010
    Posts
    1,055
    maybe you can use something like this...

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    
    </head>
    
    <body>
    <form name="myform">
    Task 1 start date: <input type="text" class="start"/><input type="button" value="-" onclick="changeDate(0,'down')"/><input type="button" value="+" onclick="changeDate(0,'up')"/><br>
    Task 2 start date: <input type="text" class="start"/><input type="button" value="-" onclick="changeDate(1,'down')"/><input type="button" value="+" onclick="changeDate(1,'up')"/><br>
    Task 3 start date: <input type="text" class="start"/><input type="button" value="-" onclick="changeDate(2,'down')"/><input type="button" value="+" onclick="changeDate(2,'up')"/><br>
    Task 4 start date: <input type="text" class="start"/><input type="button" value="-" onclick="changeDate(3,'down')"/><input type="button" value="+" onclick="changeDate(3,'up')"/><br>
    </form>
    <script type="text/javascript">
    var startDates=["4/16/2012", "5/30/2012", "2/2/2012", "12/31/2012"];
    var dateBoxes=[];
    
    var flds=document.getElementsByTagName("input");
    for (var i = 0; i < flds.length; i++) {
    if (flds[i].className=="start"){
    dateBoxes.push(flds[i])
    	} 
    }	
    
    for (var a = 0; a < dateBoxes.length; a++) {
    if (dateBoxes[a].value=startDates[a]){
    	}
    }
    
    function changeDate(num,dir){
    var diff=dir=="up"?1:-1;
    for (var a = 0; a < dateBoxes.length; a++) {
    if(a>=num){
    var d=new Date(dateBoxes[a].value);
    d.setDate(d.getDate()+diff)
    dateBoxes[a].value=(d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear()
    			}
    		}
    	}
    
    </script>
    
    </body>
    </html>

  11. #11
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    What if they do each have a unique id? Would that make it easier too? Or more difficult?

    I've got like 50+ tasks and the amount of tasks is dynamic, because the user can add/remove/change one on another page and the info is stored in the database.

    Also, I still need to be able to call it with PHP after the form is submitted... I use "$_REQUEST['start23date']" or something like that... (where 23 is the automatically-generated id number of the whole task, which gets embedded in everything)

  12. #12
    Join Date
    Nov 2010
    Posts
    1,055
    Quote Originally Posted by amandaNHT View Post
    What if they do each have a unique id? Would that make it easier too? Or more difficult?
    makes no difference to the code I posted

    Quote Originally Posted by amandaNHT View Post
    I've got like 50+ tasks and the amount of tasks is dynamic, because the user can add/remove/change one on another page and the info is stored in the database.
    interesting, but again makes no difference as long as the start date boxes have the same class name

    Quote Originally Posted by amandaNHT View Post
    Also, I still need to be able to call it with PHP after the form is submitted... I use "$_REQUEST['start23date']" or something like that... (where 23 is the automatically-generated id number of the whole task, which gets embedded in everything)
    have you tested to see if it works?

  13. #13
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Ok thanks. I was just checking to make sure nothing rang a bell for anything that might be an issue. Thanks

    I can't get to my files yet, but I'm going to integrate this as soon as I can get to them... (I'm at work, so there's a lot going on all at once)

  14. #14
    Join Date
    Apr 2011
    Location
    Seattle, WA
    Posts
    264
    Ok, so I integrated this script but now it submits when the + and - buttons get clicked.. I need it to be able to " + + + + " to add 4 days or something like that and then modify other lines below it as needed before the "submit" button gets clicked because on submit the form is going to alert everyone whose schedule was changed... and I don't want it to send 4 alerts if one task is going up 4 days, and I don't want it to send 7 alerts if task 3 is going up 4 days and task 5 goes down 3 days.

  15. #15
    Join Date
    Nov 2010
    Posts
    1,055
    Quote Originally Posted by amandaNHT View Post
    Ok, so I integrated this script but now it submits when the + and - buttons get clicked..
    assuming that you're still using this:
    Code:
    <input type="submit" value="-" class="incbutton"><input type="submit" value="+" class="incbutton">
    wouldn't the simple solution be to change it to this:
    Code:
    <input type="button" value="-" class="incbutton"><input type="button" value="+" class="incbutton">
    ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles