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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -