Jump to content

Javascript not firing correctly when called in PHP


farmallnerd

Recommended Posts

Hello, I am having trouble using Javascript with my PHP app.  I have only ever written some very basic php apps before so it is probably something simple that is going on.  Basically in the PHP I am doing a SELECT to a mysql database to find some values and I would like to use the JQuery progressbar (or any progressbar) and plug these values in so that the progressbar fills in that amount.  In the while statement I can get the outline of the bar but it will not show the value.  I thought I would test the call to that function so I commented out the value portion and added an alert instead but the page never shows that alert either so there as got to be something wrong in the way I am calling it?

while($row=mysql_fetch_array($result)){
     $percentValue = $row['percValue'];

     echo '<div id="progressbar"></div>';
}

<script>
     $(function(){
          $("#progressbar").progressbar({
              value: <?php $percentValue; ?>
          });
     });
</script>

Thanks in advance for any help you can offer!

You cannot execute JavaScript in a PHP script; and you cannot execute PHP in a JavaScript script.

 

PHP is a server-side scripting language. It executes to completion and sends something to the browser.

 

JavaScript is a client-side scripting language. It executes in the browser -- but only AFTER PHP is completely done.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.