+ Post New Thread
Results 1 to 3 of 3
Web Development Thread, Need to set focus to table cell after AJAX update and page refresh in Coding and Web Development; Hello Just signed up on recommendation of colleague. My problem is similar to 46774-html-table-change-cell-colour-value-entered.html The cell colour is not based ...
  1. #1

    Join Date
    Oct 2010
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Need to set focus to table cell after AJAX update and page refresh

    Hello

    Just signed up on recommendation of colleague. My problem is similar to

    46774-html-table-change-cell-colour-value-entered.html

    The cell colour is not based only the cell contents so cannot use if (this.value== etc )...it is based on the difference in values of two fields returned by the MySql query (sql snippet below) which is used to populate the cells. The fields are numeric representations ("ordinals") of a "current grade" and a "minimum expected grade"; so for example, if the ordinal difference is greater than +2, cell is RED and so on.

    I am using PHP and MySql.

    I use a java "onchange" script which calls an AJAX script (identified by input parameter url) to update the MySql database, which works fine

    When opening the page, I am able to set the colour correctly using CSS class ($grade_class_cag) and a routine which compares the ordinals for each cell and sets the class.

    But...... I want to change the colour immediately and also set the value of another cell on the same HTML row, depending on the ordinal difference.

    I can get the colour to change immediately if I reload the page, but that loses focus, which is unacceptable - so I have added a "refresh" button which is a sort of "quarter-way-house".

    I have thus far been unable to find a way of either

    1>> After reload, resetting the focus to the next enterable field in the row

    or

    2>> recalculating the value of the ordinal field which changes because of the user data entry/modification

    The HTML snippet which displays the cell is:-

    Code:
    <td class="gradebox '.$grade_class_cag  . '" >
        <select
            class="'.$grade_class_cag  . '" 
            OnChange="jsUpdateGradeCAG(\''.$url.'\',
                \'SCCurrentGrade\',
                this.value,
                \''.$sgc_row['ID'].'\'
                );" 
            title="Enter the Current Assessed Grade for the student"
            />';
            /****************************************************************************************/
            /* Populate option value list from coursetype grade table (05)							*/ 
            /****************************************************************************************/
            query = "
                SELECT * FROM {$_SESSION ['prf_coursetypegrade'] }  
                WHERE CGCTCode = '{$tg_row['TGCTCode']}'
                ORDER BY CGUCASPts ASC
                ";		
            if ($ctg_result = @mysql_query ($query)) {
                while ($ctg_row = mysql_fetch_array ($ctg_result, MYSQL_ASSOC)) { 
                    echo '<option value="' . $ctg_row['CGGrade'] . '">' . $ctg_row['CGGrade'] .  '</option>';
                } 
            }
            else {
                die ('Could not retrieve permitted grades for : ' . $tg_row['TGCode'] . mysql_error()); 
            };
            echo '<option selected>' .$sgc_row['CAG'] . '</option> 
        </select>
    </td>
    The SQL snippet which calculates the ordinals, using Sub Selects is:-
    Code:
    (SELECT
            ab.CBGrade AS MTG
        FROM 
            prf_vw_student_all AS st_mtg ,
            prf_alpsboundaries AS ab ,
            prf_vw_teachinggroup AS tg_mtg
        WHERE	
            tg_mtg.ID = {$_POST['txt_tg_id']} 
        AND tg_mtg.TGCTCode = ab.CBCTCode 
        AND st_mtg.ID = st.ID 
        AND st.STALISAGCSE >= ab.CBLoVal 
        AND st.STALISAGCSE < ab.CBHiVal
    ) AS ss_mtg,
    (SELECT
            ctg.CGOrdinal 
        FROM 
            prf_coursetypegrade ctg,
            prf_vw_teachinggroup tg
        WHERE	
            tg.ID = {$_POST['txt_tg_id']} 	
        and ctg.CGCTCode = tg.TGCTCode
        AND ctg.CGGrade = ss_mtg
    ) AS ss_mtg_ordinal,
    sgc.SCCurrentGrade AS CAG,
    (SELECT
            ctg.CGOrdinal 
        FROM 
            prf_coursetypegrade ctg,
            prf_vw_teachinggroup tg
        WHERE	
            tg.ID = {$_POST['txt_tg_id']} 
        and ctg.CGCTCode = tg.TGCTCode
        AND ctg.CGGrade = sgc.SCCurrentGrade
    ) AS ss_cag_ordinal,
    "st.ID" is the primary key of the student table which the main select is retrieving

    The routine then uses ss_cag_ordinal and ss_mtg_ordinal to work out what the colour should be.

    I would welcome any pointers.

    Thanks

    PS - I see that indentation tabs have disappeared on posting.
    Last edited by jneaum; 12th October 2010 at 08:37 AM.

  2. #2

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,855
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    181
    Quote Originally Posted by jneaum View Post
    PS - I see that indentation tabs have disappeared on posting.
    Wrap it in [ code ] tags (collapse those spaces).

    Everything would be far easier to read if you used a proper templating engine, like smarty...

  3. #3

    Join Date
    Oct 2010
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Powdermonkey - Thanks for the [code] tag information.

SHARE:
+ Post New Thread

Similar Threads

  1. Webpage refresh on page load
    By timbo343 in forum Web Development
    Replies: 2
    Last Post: 29th March 2010, 12:27 PM
  2. hta to update / add to specific cell
    By mac_shinobi in forum Scripts
    Replies: 1
    Last Post: 12th February 2010, 05:53 PM
  3. Making a web page refresh at set intervals
    By farquea in forum Windows
    Replies: 7
    Last Post: 12th February 2010, 02:17 PM
  4. Replies: 2
    Last Post: 15th December 2009, 03:36 PM
  5. Update Active Directory with mySQL table data?
    By netadmin in forum Windows
    Replies: 8
    Last Post: 30th October 2007, 10:43 PM

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
  •