Javascript function with vars on PHP print: quotes -


i wondering if there better way write down php vars passed javascript function called inside php print.:

while($nav = mysqli_fetch_array($nav_db)){     print  '<li>              <a href="#" onclick="getproductpage('.$nav['id'].', \''.$name.'\')">                        '.$nav['data'].'               </a>         </li>'; } 

where

$nav['id'] 

is integer don't need '' js, and

$name 

is not integer need \' \' js.

especially step:

getproductpage('.$nav['id'].', \''.$name.'\') 

thank you

<?php while($nav = mysqli_fetch_array($nav_db)): ?>   <li>      <a onclick="getproductpage(<?php echo $nav['id']; ?>, '<?php echo $name; ?>')">         <?php echo $nav['data']; ?>      </a>   </li> <?php endwhile; ?> 

you should break out of php write html. cleaner way. also, had rogue </span> in there , no need <br> in <li> menu. also, a tag should have href value in there, if # or javascript:void(0) or something.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -