php - how to set default la page as default in css -


i have been struggled 1 sticky issue regarding set default li.

what try achieve set li , related page default one. , when users click on others links, load other pages.

html markup:

  <div id="productintro">      <div id="leftnav">         <ul>            <li class="head">               <a href="javascript:void(0)" onclick="show('.$row["id"].',1);"> pictures</b></a>            </li>            <li class="head">               <a href="javascript:void(0)" onclick="show('.$row["id"].',2);"> <b>comments</b></a>            </li>            <li class="head">               <a href="javascript:void(0)" onclick="show('.$row["id"].',3);"> <b>others</b></a>            </li>         </ul>      </div>      <div class="main">      </div>   </div> 

js:

        function show(id, page) {            $('.main').load("loadprodetail.php?id=" + id + "&page=" + page, true);         }         jquery(document).ready(function () {            $(document).on('click', '.head', function () {               $(".head").removeclass("selected");               $(this).toggleclass("selected");            });         }); 

loadprodetail php

  <?php   $id = $_get['id'];   $sql = "select * product id=$id ";   $result = mysql_query($sql);   $row = mysql_fetch_assoc($result);   $page = $_get['page'];   if($page == 1)   {      $html .= '<img src="./product_images/' . $row["name"] . '.jpg" width="150" border="2">';   }   if($page == 2)   {      $html .= 'no comments far';   }   if($page == 3)   {      $html .= 'this page under construction';   }   echo $html; 

css:

.selected{background-color:red;} 

in case, want set "picutre" li default page, , when user click on comments, load corresponding page. , background colour should changed.

your page logic lives in php, specifying page should display default can added there modifying if statements , making them if...else instead:

if ($page==2) {      $html .= 'no comments far'; } else if ($page==3) {      $html .= 'this page under construction'; } else {      $html .= '<img src="./product_images/'.$row["name"].'.jpg" width="150" border="2">'; } 

the logic implemented above goes this: if "comments" or "others" pages requested, serve them, if not serve "pictures" page.

since want load "picture" content when page loaded, can call show() function in javascript on pageload. adding following line existing jquery(document).ready(function () { ... } should work long $row["id"] set:

show($row["id"], 1); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -