Solved

php java dropdowns

Posted on 2013-10-24
20
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
20 Comments
 
LVL 22

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 110

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 110

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 110

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 110

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
 
LVL 110

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 110

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 110

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 110

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change Wording in Wordpress Plugin 4 40
jquery change div image on page reload using Jquery 9 61
Javascript question 8 44
How to strip HTML from this JS code using regex 29 46
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

752 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