Jump to content

Javascript in PHP Code


eits

Recommended Posts

Hi I am trying to get a selectbox to populate when another selectbox value changes however I cannot seem to get anything to work with 'onchange' event of the select box (I tried even just popping up a msg box upon change but it isnt doing anything).

 

Could somebody tell me if I am supposed to do anything special to get Javascript to work in a PHP code? Here is the selectbox code and JS anyway.

 

 <script language="javascript">
    function jobnums()
var choice = document.form1.clientname.options[document.form1.clietname.selectedIndex].value;
    window.alert("Click OK and I'll sum your numbers!");
{
        $query_rsjobdb = "SELECT * FROM jobdb";
$rsjobdb = mysql_query($query_rsjobdb, $timedb) or die(mysql_error());
$row_rsjobdb = mysql_fetch_assoc($rsjobdb);
$totalRows_rsjobdb = mysql_num_rows($rsjobdb);

    }
    </script>

 

and the selectbox code:

 

<select name="clientname" id="clientname" onchange="jobnums()">
        <?php do { ?>
        <option value="<?php echo $row_rscustdb['clientname']?>" selected="<?php $row_custdb['clientname'] ?>"> <?php echo $row_rscustdb['clientname']?></option>
        <?php
} while ($row_rscustdb = mysql_fetch_assoc($rscustdb));
  $rows = mysql_num_rows($rscustdb);
  if($rows < 10) {
      mysql_data_seek($rscustdb, 0);
  $row_rscustdb = mysql_fetch_assoc($rscustdb);
  }
?>
      </select>

Link to comment
Share on other sites

Let's see let's cut up your code and see if we can find out what the problem is....

Ok you can't use it like that.

The database queries inside of javascript are not going to work.

They are php not javascript that is impossible.

You can pass variables "to" javascript though and vice versa in a few situations (very few).

You are going to need to look into ajax to do a call to a server side php page to perform the actions.

Do some checking on ajax and get the basic concepts then post back here when you have something basic to look at.

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.