Solved

php java dropdowns

Posted on 2013-10-24
20
248 Views
Last Modified: 2013-11-01
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
Comment
Question by:doctorbill
  • 11
  • 8
20 Comments
 
LVL 21

Assisted Solution

by:Kim Walker
Kim Walker earned 56 total points
ID: 39597119
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597120
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
 

Author Comment

by:doctorbill
ID: 39597178
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
 

Author Comment

by:doctorbill
ID: 39597235
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 444 total points
ID: 39597275
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
 

Author Comment

by:doctorbill
ID: 39597311
Ray - how do I then check what is being passed to the browser from your script above
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597320
Use "view source."
0
 

Author Comment

by:doctorbill
ID: 39597366
Nothing comes through - would it be in the head or body section
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597392
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
 

Author Comment

by:doctorbill
ID: 39597437
Can you tell me how to specify where the echo $jss; is sent so I can see the value of it
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597504
What is the URL of the web page?
0
 

Author Comment

by:doctorbill
ID: 39597544
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597702
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
 

Author Comment

by:doctorbill
ID: 39597958
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39597975
Just a thought... Where is the <?php tag?
0
 

Author Comment

by:doctorbill
ID: 39598016
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
 

Author Comment

by:doctorbill
ID: 39598077
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
 

Author Comment

by:doctorbill
ID: 39599831
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 444 total points
ID: 39608941
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
 

Author Closing Comment

by:doctorbill
ID: 39617514
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now