www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Fill in Values from last value inputted

  1. #1
    Join Date
    Oct 2010
    Posts
    45

    resolved [RESOLVED] Fill in Values from last value inputted

    I am trying to get a multiple row/column form table to fill down the last value inputted in a textbox on a column to the rest of the textboxes in that column when a button or checkbox is selected. I am a total novice at JavaScript and have only been able to do a simple example but it's hardcoded to only use the value from the first textbox, not the last textbox that had a value. And I'm not sure how to accomodate multiple columns with this feature.

    Any help would be great.

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    var grade1 = "";
    var grade2 = "";
    var grade3 = "";
    var grade4 = "";
    var grade5 = "";
    var grade6 = "";
    /*  Save the inputted grades so far */
    function InitSaveVariables(form) {
    grade1 = form.grade1.value;
    grade2 = form.grade2.value;
    grade3 = form.grade3.value;
    grade4 = form.grade4.value;
    grade5 = form.grade5.value;
    grade6 = form.grade6.value;
    }
    /* if checked, fill down from grade1 else unchecked return values to previous value */
    function FillDown(form) {
    if (form.copy.checked) {
    InitSaveVariables(form);
    form.grade1.value = form.grade1.value;
    form.grade2.value = form.grade1.value;
    form.grade3.value = form.grade1.value;
    form.grade4.value = form.grade1.value;
    form.grade5.value = form.grade1.value;
    form.grade6.value = form.grade1.value;
    }
    else {
    form.grade1.value = grade1;
    form.grade2.value = grade2;
    form.grade3.value = grade3;
    form.grade4.value = grade4;
    form.grade5.value = grade5;
    form.grade6.value = grade6;
       }
    }
    </script>
    
    </head>
    <body>
    <center>
    <form method="post" action="" name="testform">
    <table border="1" cellspacing="0" cellpadding="3" width="400">
    
    <tr bgcolor="#003399">
    <td colspan=3 width="100%" bgcolor="#003399">
    <b><font color=white size="-1" face="arial, helvetica">Fill Down Test</font></b>
    <font color=white size="-2" face="arial, helvetica">
    (Check to use Fill Down: <input type="checkbox" name="copy"
    OnClick="javascript:FillDown(this.form);" value="checkbox"> )</font>
    </td>
    </tr>
    <tr>
        <td>Student</td><td>Test 1</td><td>Test 2</td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 1:</font>
    </td>
    <td>
    <input type="text" size="5" name="grade1">
    </td>
    <td>
    <input type="text" size="5" name="grade1a">
    </td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 2:</font>
    </td>
    <td>
    <input type="text" size="5"name="grade2">
    </td>
    <td>
    <input type="text" size="5"name="grade2a">
    </td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 3:</font>
    </td>
    <td>
    <input type="text" size="5" name="grade3">
    </td>
    <td>
    <input type="text" size="5" name="grade3a">
    </td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 4:</font>
    </td>
    <td>
    <input type="text" size="5" name="grade4">
    </td>
    <td>
    <input type="text" size="5" name="grade4a">
    </td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 5:</font>
    </td>
    <td>
    <input type="text" size="5" name="grade5">
    </td>
    <td>
    <input type="text" size="5" name="grade5a">
    </td>
    </tr>
    <tr>
    <td>
    <font size="-1" face="arial, helvetica">Student 6:</font>
    </td>
    <td>
    <input type="text" size="5" name="grade6">
    </td>
    <td>
    <input type="text" size="5" name="grade6a">
    </td>
    </tr>
    
    </table>
    </form>
    </center>
    
    </body>
    </html>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Fill Down Test</title>
    
    <script type="text/javascript">
    window.onload=function() {
    var aObj = document.getElementsByTagName('input');
    var i = aObj.length; 
    while(i--) { 
        if(aObj[i].type=='text') {
        	aObj[i].onchange = function() {down[this.parentNode.cellIndex] = this.parentNode.parentNode.rowIndex;};
            }
        else {
            aObj[i].onclick = function() {fillDown(this);};
            }
        }
    };
    
    var down = [];
    function fillDown(obj) {
    var aObj = document.getElementsByTagName('tr');
    var len = aObj.length; 
    var col = obj.parentNode.cellIndex;
    var val = aObj[down[col]].getElementsByTagName('input')[col-1].value;
    for(var i=down[col]; i<len; i++) {
        aObj[i].getElementsByTagName('input')[col-1].value = val;
        }
    };
    </script>
    
    <style type="text/css">
    body {
    font-family:Arial, Helvetica, sans-serif;
    font-size:0.8em;
    color:#000;
    background:#fff;
    }
    table {
    border:1px solid;
    border-collapse:collapse;
    width:400px; 
    margin:auto;
    }
    th {
    color:#fff;
    background:#039;
    }
    th, td {
    border:1px solid;
    padding:3px;
    }
    input[type='button'] {
    font-size:smaller;
    }
    </style>
    
    </head>
    <body>
    <form method="post" action="#" name="testform">
    <table>
    <thead>
        <tr>
            <th colspan="3">Fill Down Test</th>
        </tr>
        <tr>
            <th>Click to use Fill Down:</th>
            <th><input type="button" name="copy" value="copy"></th>
            <th><input type="button" name="copy" value="copy"></th>
        </tr>
        <tr>
            <th>Student</th>
            <th>Test 1</th>
            <th>Test 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Student 1:</td>
            <td><input type="text" size="5" name="grade1"></td>
            <td><input type="text" size="5" name="grade1a"></td>
        </tr>
        <tr>
            <td>Student 2:</td>
            <td><input type="text" size="5" name="grade2"></td>
            <td><input type="text" size="5" name="grade2a"></td>
        </tr>
        <tr>
            <td>Student 3:</td>
            <td><input type="text" size="5" name="grade3"></td>
            <td><input type="text" size="5" name="grade3a"></td>
        </tr>
        <tr>
            <td>Student 4:</td>
            <td><input type="text" size="5" name="grade4"></td>
            <td><input type="text" size="5" name="grade4a"></td>
        </tr>
        <tr>
            <td>Student 5:</td>
            <td><input type="text" size="5" name="grade5"></td>
            <td><input type="text" size="5" name="grade5a"></td>
        </tr>
        <tr>
            <td>Student 6:</td>
            <td><input type="text" size="5" name="grade6"></td>
            <td><input type="text" size="5" name="grade6a"></td>
        </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Oct 2010
    Posts
    45

    Genius!

    Thank you! A wonderfully simple example that works great. I really appreciate your help!

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10189 seconds
  • Memory Usage 2,874KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates