Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 04-15-2011, 05:14 PM Skipping code
Extreme Talker

Posts: 173
Trades: 0
I have this code that is part of a larger php file which I am struggling with.

I am trying to pass in a variable from php 'aoa' which is a date, but when the program runs to the first line of javascript code, it does not process the variable being passed in and just jumps out of the script and continues on with the php. Any suggestions?

PHP Code:
    textbox_list("Name","input","project_desc",$row['project_desc'],45,$tab++).
    '<li><label for="aoa">AOA:</label>';
?>
<script>
var check_date='<?php echo $row['aoa']; ?>';
document.write(check_date)
    if (!check_date){
      DateInput('ship_date')
    } 
    else{ 
     DateInput('ship_date', false, 'YYYY-MM-DD',check_date)
    }
</script>
<?php
    
echo '</li>'.
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-15-2011, 05:22 PM Re: Skipping code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Javascript only runs once the page is served to the client browser and php scripting is over and done by then.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-16-2011, 12:04 AM Re: Skipping code
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Javascript only runs once the page is served to the client browser and php scripting is over and done by then.
Exactly.

You can use php to write Javascript but I don't think you need to in this case - just remove the document.write line and access the variable by its DOM reference. Read the tutorials on http://www.w3schools.com/htmldom/default.asp if you want good basic info.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 04-16-2011, 09:48 AM Re: Skipping code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Hijack post moved to here
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-23-2011, 02:09 PM Re: Skipping code
Extreme Talker

Posts: 173
Trades: 0
Guys, thanks for the replies. I understand what you mean about it php is over and done with but still cannot figure this out.

This is the link to the source code for the calendar that I am trying to incorporate into the site.

http://www.dynamicdrive.com/dynamici...oncalendar.htm

To your point Chirshirst, I tried to modify the code by removing the if statement to be part of the php so that is decides which bit of javascript should be used.

I also thought as you pointed out about javascript running on the client side that I should then try to echo the statement so that it get interpreted by the brouser, but that did not lead me to any further success.

I have attached all the code below as well for reference.

Bit more help please.

PHP Code:
if(empty($row['aoa'])) {
 ?>
 <script>
 var check_date='<?php echo $row['aoa']; ?>';
 DateInput('aoa')
 </script>
 <?php
}
else{
 
?>
 <script>
 var check_date='<?php echo $row['aoa']; ?>';
 DateInput('aoa', false, 'YYYY-MM-DD','<?php echo $row['aoa']; ?>')
 </script>
 <?php
}

PHP Code:
<?php
// start session 
session_start();
// set up some global variables 
@include 'menu.php';
echo 
'<link rel="stylesheet" type="text/css" href="style/form_style.css" />';
if(isset(
$_POST['project'])){
$field_list=array( 'work_flow',   'network_number''documentum',   'pdit',    
     
'xfer_service',   'service_request''wt_accept',   'wt_ship',   
     
'aoa',     'inco_term',  'inco_place',   'rdd',     
     
'transit_time',   'ship_date',  'st_cd',    'float',
     
'st_courier',   'st_email',   'st_ftp',    'review_period',
     
'submit_office',  'document_level''margin_level',   'contigency',
     
'financials',   'owner',   'customer',    'consultant',
     
'project',    'project_desc');
 foreach (
$_POST as &$field){
  
$field=sanitizeMySQL($field);
 }
 if(!empty(
$_POST['consultant']))$_POST['consultant']=lookup("tbl_company",$_POST['consultant'],"company","company_id");
 if(!empty(
$_POST['customer'])) $_POST['customer']=lookup("tbl_company",$_POST['customer'],"company","company_id");
 if(!empty(
$_POST['owner']))  $_POST['owner']=lookup("tbl_company",$_POST['owner'],"company","company_id");
}
//Update Project details
if(!empty($_POST['project_id'])){
 
update("tbl_project",$field_list,$_SESSION['project_id']);
 echo 
'<head>'.
   
'<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=display_project_details.php?project_id='.$_SESSION['project_id'].'">'.
   
'Project details updated.</head>';
 die;  
}
$sql='SELECT * FROM tbl_project WHERE project_id='.$_SESSION['project_id'];
$row mysql_fetch_assoc(query($sql));
$tab=0;
//Starts form
echo '<html><head>'.
 
'<script type="text/javascript" src="calendarDateInput.js">'.
 
/****************************************************************************************
 * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
 * Script featured on and available at http://www.dynamicdrive.com
 * Keep this notice intact for use.
 *****************************************************************************************/
 
'</script>';
 echo 
'</head>'.
 
'<body>'.
  
'<form id="display_project_details" name="display_project_details" action="display_project_details.php" method=post>'.
  
btn_update().
  
textbox_list("","hidden","project_id",$_SESSION['project_id'],0,$tab++).
  
'<ul>'
   
'<fieldset><legend>Project</legend>'.
    
textbox_list("Project","input","project",$row['project'],45,$tab++).
    
textbox_list("Name","input","project_desc",$row['project_desc'],45,$tab++).
    
'<li><label for="aoa">AOA:</label>';
 
if(empty(
$row['aoa'])) {
 
?>
 <script>
 var check_date='<?php echo $row['aoa']; ?>';
 DateInput('aoa')
 </script>
 <?php
}
else{
 
?>
 <script>
 var check_date='<?php echo $row['aoa']; ?>';
 DateInput('aoa', false, 'YYYY-MM-DD','<?php echo $row['aoa']; ?>')
 </script>
 <?php

    echo 
'</li>'.
    
textbox_list("Network Number","input","network_number",$row['network_number'],255,$tab++).
   
'</fieldset>'.
   
'<fieldset><legend>Customers</legend>'.
    
dropdown("owner","Site Owner","company","company_id","company","tbl_company",$row['owner'],$tab++).
    
dropdown("customer","Customer","company","company_id","company","tbl_company",$row['customer'],$tab++).
    
dropdown("consultant","Consultant","company","company_id","company","tbl_company",$row['consultant'],$tab++).
   
'</fieldset>'.
   
'<fieldset><legend>Shipping</legend>'.
    
dropdown("inco_term","INCO Term","inco","inco","inco","tbl_list_inco_terms",$row['inco_term'],$tab++).
    
textbox_list("Named Place","input","inco_place",$row['inco_place'],45,$tab++).
    
'<li><label for="rdd">Requested Delivery Date:</label>';
    
?>
    <script>
     var check_date='<?php echo $row['rdd']; ?>';
     if (!check_date){
      DateInput('rdd')
     } 
     else{ 
      DateInput('rdd', false, 'YYYY-MM-DD',check_date)
     }
    </script>
    <?php
    
echo textbox_list("Float","input","float",$row['float'],45,$tab++).
    
textbox_list("Transit Time","input","transit_time",$row['transit_time'],45,$tab++).
    
'<li><label for="ship_date">Ship Date:</label>';
    
?>
    <script>
     var check_date=new var('<?php echo $row['ship_date']; ?>');
     if (!check_date){
      DateInput('ship_date')
     } 
     else{ 
      DateInput('ship_date', false, 'YYYY-MM-DD',check_date)
     }
    </script>
    <?php
    
echo '</li>'.
   
'</fieldset>'.
   
'<fieldset><legend>URL Addresses</legend>'.
    
textbox_list("Workflow","input","work_flow",$row['work_flow'],255,$tab++).
    
textbox_list("Documentum","input","documentum",$row['documentum'],255,$tab++).
    
textbox_list("Transfer to Service","input","xfer_service",$row['xfer_service'],255,$tab++).
    
textbox_list("PDIT","input","pdit",$row['pdit'],255,$tab++).
    
textbox_list("Service Request","input","service_request",$row['service_request'],255,$tab++).
   
'</fieldset>'.
   
'<fieldset><legend>Warranty</legend>'.
    
textbox_list("Accepted","input","wt_accept",$row['wt_accept'],45,$tab++).
    
textbox_list("Shipped","input","wt_ship",$row['wt_ship'],45,$tab++).
   
'</fieldset>'.
   
'<fieldset><legend>Document Transmittals</legend>'.
    
textbox_list("CD","input","st_cd",$row['st_cd'],45,$tab++).
    
textbox_list("Courier","input","st_courier",$row['st_courier'],45,$tab++).
    
textbox_list("email","input","st_email",$row['st_email'],45,$tab++).
    
textbox_list("FTP","input","st_ftp",$row['st_ftp'],45,$tab++).
    
textbox_list("Review Period","input","review_period",$row['review_period'],45,$tab++).
    
textbox_list("Submitting Office","input","submit_office",$row['submit_office'],45,$tab++).
    
textbox_list("Document Leveling","input","document_level",$row['document_level'],45,$tab++).
   
'</fieldset>'.
   
'<fieldset><legend>Variation Costing</legend>'.
    
checkbox("Margin Leveling","margin_level",$row['margin_level'],$tab++).
    
textbox_list("Contingency","input","contigency",$row['contigency'],5,$tab++).
    
textbox_list("Finacials","input","financials",$row['financials'],5,$tab++).
   
'</fieldset>'.
  
'</ul>'.
 
  
'</form>'.
   
'</body></html>';  
?>
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 04-23-2011, 02:14 PM Re: Skipping code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What are you expecting the javascript to do?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-23-2011, 05:24 PM Re: Skipping code
Extreme Talker

Posts: 173
Trades: 0
Depending on whether the variable $row['aoa'] is null or not it needs to change the way it calls the function DateInput.
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 04-23-2011, 06:14 PM Re: Skipping code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
And what does or does not happen?

Because we can't recreate any of this without your database.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-23-2011, 06:43 PM Re: Skipping code
Extreme Talker

Posts: 173
Trades: 0
I have checked that the value $row['aoa'] is correctly registering the value that it should. When I try to run the code, I currently getting the following error message

Quote:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\Documents and Settings\414004425\My Documents\pet\display_project_details.php on line 64
Line 64 is the var check_date line

PHP Code:
if(empty($row['aoa'])) {
 echo'<script>'.
 'var check_date=<?php echo $row['aoa']; ?>'.
 'DateInput('check_date')'.
 '</script>';
 
}
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 04-24-2011, 04:47 AM Re: Skipping code
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
'var check_date=<?php echo $row['aoa']; ?>'.

should be = $row['aoa'] ie remove the echoing! Sort out the quotes and check your IF condition - should that be !empty ?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 04-24-2011, 07:48 AM Re: Skipping code
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
What about just changing the whole bit to..

$blaa = $row['aoa'];
if(empty($row['aoa'])) {
echo '<script>
var check_date='.$blaa.'
DateInput(\'check_date\')
</script>';

}
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 04-25-2011, 11:20 AM Re: Skipping code
Extreme Talker

Posts: 173
Trades: 0
In response to PaulW, don't you need to have the $row['aoa'] as a php variable that needs to be passed into the script hense the need for the <?php...?>?
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 04-25-2011, 04:58 PM Re: Skipping code
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Quote:
Originally Posted by dgkindy View Post
In response to PaulW, don't you need to have the $row['aoa'] as a php variable that needs to be passed into the script hense the need for the <?php...?>?
No. What you're doing is building up a string - the fact that it's Javascript is irrelevant - you're not "passing values" to anything. It's the same as $str = "the value = " . $row['aoa'] . " some more text";
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE

Last edited by PaulW; 04-25-2011 at 04:59 PM..
PaulW is online now
Reply With Quote
View Public Profile
 
Old 04-30-2011, 07:02 PM Re: Skipping code
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
That is; that code snippet should be

PHP Code:
if(empty($row['aoa'])) {
   echo 
"<script>"
      
"var check_date=" $row['aoa'] . ";"
      
"DateInput('check_date');"
      
"</script>";

Although, as Paul pointed out. You probably don't want to use the row data if it's empty. So maybe the check_date variable should get another value?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Skipping code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.68571 seconds with 12 queries