eits Posted September 9, 2007 Share Posted September 9, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/68592-javascript-in-php-code/ Share on other sites More sharing options...
Ninjakreborn Posted September 9, 2007 Share Posted September 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/68592-javascript-in-php-code/#findComment-344797 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.