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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.