Link to home
Start Free TrialLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php java dropdowns

The following script changes the value of one drop box according to the value of another one
This is working finr on my php page

I need the following:
The variable #status needs to be defined from a php variable "statuscompleted[<?php echo $row_orders['ID']; ?>]"
The variable #currentstatus needs to be defined from a php variable "build[<?php echo $row_orders['ID']; ?>]"

<script src="jquery/jquery-1.8.3.min.js">
</script>

<script type="text/JavaScript">
jQuery(document).ready(function($) {
      $("#status").change(function(){
            if($("#status").val()=="Completed"){
                  $("#currentstatus").val("Completed");
            }
            
      });      
});
</script>

What I need to know is how to define the php variables so the javascript can use them
SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doctorbill

ASKER

If you already have these elements generated with different ids, modify the jQuery code and replace "#status" and "#currentstatus" with the ids of those elements.

This is the problem
the elements are :

id = "statuscompleted[<?php echo $row_orders['ID']; ?>]"
id ="build[<?php echo $row_orders['ID']; ?>]"

How exactly do I get these into the jQuery - cpuld you please show in the posted script please?
Ray:
How do I do this please - in my code

'So all you need to do is place the PHP echo statements into the string variable that contains the JavaScript.'
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray - how do I then check what is being passed to the browser from your script above
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nothing comes through - would it be in the head or body section
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you tell me how to specify where the echo $jss; is sent so I can see the value of it
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
http://localhost/comwebsites/1callorders/site/orders_find_visit_print_custom_status_noforms_nocosts_idfilter2.php?p=1&ID[64]&ID[63]&ID[62]&ID[61]&ID[69]&pldte=97&sourcedte=August%2031,%202012%209:16am#anchor5
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just noticed something:

The "$jss = <<<EOD" appears to be unrecognised by the page and the whole script is printed on the page
I have only noticed it because the background was black before and it did not show up
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am just using this in the head section of my page (i already have a reference to the jquery file):
---------------------------------
<head>
......


$jss = <<<EOD
<script type="text/JavaScript">
jQuery(document).ready(function($) {
      $("#status").change(function(){
            if($("#status").val()=="$row_orders->ID"){
                  $("#currentstatus").val("$row_orders->ID");
            }
           
      });      
});
</script>
EOD;

// WRITE THE JAVASCRIPT TO THE BROWSER
echo $jss;

</head>
ooops - looks like I forgot php tags
where exactly should they be on the script above ? - should this be in the section above the <head> tag, between php tags?
This is the script as it is now in my page:
I still do not see anything being returned
Sorry but I can't put this on a public server yet - no access to it

<?php
/**
 * RUN THE QUERY AND ACQUIRE THE ROW FROM THE RESULTS SET
 * USE OBJECT-ORIENTED NOTATION TO RECOVER THE ROW (EASIER PUNCTUATION)
 */

// USE HEREDOC NOTATION TO CREATE THE JAVASCRIPT STRING
$jss = <<<EOD
<script type="text/JavaScript">
jQuery(document).ready(function($) {
      $("#status").change(function(){
            if($("#status").val()=="$row_orders->ID"){
                  $("#currentstatus").val("$row_orders->ID");
            }
           
      });      
});
</script>
EOD;

// WRITE THE JAVASCRIPT TO THE BROWSER
echo $jss;
?>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks