Solved

php java dropdowns

Posted on 2013-10-24
20
252 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 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 109

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 109

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 109

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 109

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 109

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 109

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 109

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 109

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery 10 20
php mysql check email already in database. (second check) 7 30
PHP Syntax Error 4 27
How do I fix this UPDATE error? 7 24
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

810 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