• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

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
0
doctorbill
Asked:
doctorbill
  • 11
  • 8
9 Solutions
 
Kim WalkerWeb Programmer/TechnicianCommented:
I think there's a disconnect in your terminology. "#status" is not a variable. Neither is "statuscompleted[<?php echo $row_orders['ID']; ?>]" a variable. So it's difficult to determine what you're asking.

$("#status").val() is the value of the element whose id is "status". Likewise, $("#currentstatus").val is the value of the element whose id is "currentstatus". These elements would likely be text input elements. Your PHP script would need to generate two input elements:
<input type="text" id="status" name="somename" value="somevalue">
<input type="text" id="currentstatus" name="someothername" value="somevalue">

Open in new window

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.
0
 
Ray PaseurCommented:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

PHP runs on the server and prepares the JavaScript that gets sent to the client.  By the time the client starts to run the JavaScript (in this case, jQuery) PHP has finished and the server is disconnected.  So all you need to do is place the PHP echo statements into the string variable that contains the JavaScript.
0
 
doctorbillTechAuthor Commented:
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?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
doctorbillTechAuthor Commented:
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.'
0
 
Ray PaseurCommented:
I may not be understanding this correctly, and I don't have any test data, so this may or may not be useful to you.

<?php // RAY_temp_doctorbill.php
error_reporting(E_ALL);

/**
 * 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;

Open in new window

It's possible that you're looking for a jQuery/AJAX implementation.  If that's the case, here is the "hello world" exercise that you would need to understand in order to connect the web page on the client to the PHP application on the server.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 
doctorbillTechAuthor Commented:
Ray - how do I then check what is being passed to the browser from your script above
0
 
Ray PaseurCommented:
Use "view source."
0
 
doctorbillTechAuthor Commented:
Nothing comes through - would it be in the head or body section
0
 
Ray PaseurCommented:
What is the URL of the web page?

The output from the $jss variable would appear where you sent it - head or body.  Probably body, but that would be under the control of your PHP logic.
0
 
doctorbillTechAuthor Commented:
Can you tell me how to specify where the echo $jss; is sent so I can see the value of it
0
 
Ray PaseurCommented:
What is the URL of the web page?
0
 
doctorbillTechAuthor Commented:
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
0
 
Ray PaseurCommented:
Please put the scripts on a public-facing server and post a link to the URL so that we can use a web browser to see the output.  Then we can use "view source" to see what HTML has been generated.  Thanks, ~Ray
0
 
doctorbillTechAuthor Commented:
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
0
 
Ray PaseurCommented:
Just a thought... Where is the <?php tag?
0
 
doctorbillTechAuthor Commented:
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>
0
 
doctorbillTechAuthor Commented:
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?
0
 
doctorbillTechAuthor Commented:
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;
?>
0
 
Ray PaseurCommented:
These lines are comments, meant to communicate information to humans, as opposed to computers.  You would need to do what they tell you.  You would connect to the data base engine, select a data base, run a query to get a row from the data base into a variable named $row_orders

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

Open in new window

0
 
doctorbillTechAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 11
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now