Jump to content

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


Recommended Posts

Posted (edited)

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:-

 

           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 '' . $ctg_row['CGGrade'] .  '';
           } 
       }
       else {
           die ('Could not retrieve permitted grades for : ' . $tg_row['TGCode'] . mysql_error()); 
       };
       echo '' .$sgc_row['CAG'] . ' 
   

 

The SQL snippet which calculates the ordinals, using Sub Selects is:-

(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.

Edited by jneaum
Posted
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...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...