CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Auto display the first record inside the view area on page load  (Read 84 times)

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
preface:   for my instant messages feature i wanted to auto load the first record so the user can see when the page loads.   Originally when the page loaded both items in the picture (leftside) were both grey meaning they were both unread messages, but the (right side page) view area was blank.   I wanted to load the first record automatically by adding a autoclick function if it was the first record only.

Now as you can see in the pic when i do this it takes the grey background off the first record because the click marks it as read.   I know i can fix that by setting the background in my function code included here.  So that part is fine.  (well it might be alittle more difficult than i thought because its marked read after this function loads, but ill figure it out)

The auto click is working, but I wanted to share this just to be sure i am doing this correctly and not using crapola code to do this.

here is the php, html and js autoclick code and i pic.

Code: [Select]

    <?php
    $i 
1;
                          
                           
//this will allow for the first message in the array to be 
                           //auto displayed, then the rest of the array will load normally
                           //and only be viewed on click

                           //the last item in the IMessageAction function (0 or 1) is the isread field   
                           //for the first record its set to 0 (unread) so it is not marked 
                           //as read on autoview
                           //then all other records are loaded normally with the click and 
                           //set to 1 (read) when clicked

                           //however this logic is not working correctly, so i might just 
                          //give up on this idea of autoload first record and just put text 
                          //on the left on page load that says "click subject of message to view here"
                          
                            
if($i == 1)
                            {

                              
//in this case call the loadfirst id on the first record
                                
                              
echo '<a href="javascript:void(0);" title="Click To View" id="loadfirst" onClick="IMessageAction('.(int) $intmes_id.','.(int) $intmes_from.',\''.$ajax_int_messages.'\',\''.$username.'\','.(int) $sess_uid.',0)">'.htmlspecialchars($intmes_subject).'</a>';
     
                              
$i 2//will remain 2 after this, and avoiding this id  
                                
                            
}else{
                                  
//loadfirst id does not exist for the rest of the records
                                
                                   
echo '<a href="javascript:void(0);" title="Click To View" onClick="IMessageAction('.(int) $intmes_id.','.(int) $intmes_from.',\''.$ajax_int_messages.'\',\''.$username.'\','.(int) $sess_uid.',1)">'.htmlspecialchars($intmes_subject).'</a>';

                                 }
//close else i
                          
                           
?>

                                 
     

and the js

Code: [Select]
<script>
   
"use strict";

window.onload = function()
{
   
 var lf = document.getElementById('loadfirst'); 
 
 if(lf)
 {
     
   lf.click(); 
     
 }
 
}//close window load
   
</script>


and a pic  items are the left are viewed on the right on click.

https://photos.app.goo.gl/XThfAdvAzVhWezwp6



« Last Edit: 20 Nov 2023, 04:49:32 am by durangod »

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: Auto display the first record inside the view area on page load
« Reply #1 on: 20 Nov 2023, 05:29:04 am »
Yeah i gave up on the idea, it just causes havoc in an otherwise perfect running feature.  Either the clicks dont work, or they are opposite, or they are grey (unread) when they should be not gray (read), one thing after another. 

So i disabled that feature code and i added a default text in the subject line of the message view div (which the data  is controlled by js) that reads "Click Message Subject To View Message"   then when i click the subject js with overwrite the div (getting rid of the default message) and showing the message data.

here is the pic

https://photos.app.goo.gl/36KRGoapy73V45BK7



 

SMF spam blocked by CleanTalk

Advertisement