1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What's wrong with this syntax?

Discussion in 'PHP' started by lost, Nov 15, 2005.

  1. Mat

    Mat Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #21
    I don't think you need to use the php init() function more than once.
     
    Mat, Nov 16, 2005 IP
  2. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #22
    in a way you're right...i think i have it poorly named.
    however, that method needs to be constantly checked...so i do have to call it again and again
     
    lost, Nov 16, 2005 IP
  3. torunforever

    torunforever Peon

    Messages:
    414
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #23
    I've been making suggestions to solve specific problems in your code, while all along I should have been questioning the overall functionality. Unfortunately I haven't gotten a chance to look carefully at your code, so I'll just offer another specific suggestion.

    Make sure your html is layed out in the following basic layout:

    <html>
    <head>
    <script etc.>
    javascript goes here
    </script>
    </head>
    <body>
    <form etc.>
    php goes here
    </form>
    </body>
    </html>

    Don't put the body above the opening html tag.
     
    torunforever, Nov 16, 2005 IP
  4. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #24
    waaaaaaaaaaaaaaaaaaaaaaaaaaa :(

    I hate this!!!!
     
    lost, Nov 16, 2005 IP
  5. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #25
    Can you post the entire file you are having problems with? Then we might be able to find the error.
     
    exam, Nov 16, 2005 IP
  6. Delta-Biz

    Delta-Biz Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #26
    I don't see session_start(); anywhere.. Has to be at the top before anything is output. And i might be missing something but this line <?php $_SESSION['genericNewConfig'] = true; ?> will set the session variable to true. So when init() runs the variable will always be true.
     
    Delta-Biz, Nov 16, 2005 IP
  7. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #27
    the session_start() is done in the .php file.
    and you're right, this line <?php $_SESSION['genericNewConfig'] = true; ?> will always set the session variable to true, but this is what i want when the createNewConfig() method is called.
     
    lost, Nov 17, 2005 IP
  8. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Here's the entire file, please someone help me find the syntax errors!

    
    <FORM ID="genericform" ACTION="systemconfig-generic.php" METHOD="post">
      <BR>
      <BR>
      
      <?php
        init();
      ?>
    
      <CENTER><INPUT TYPE=button VALUE="Create New Configuration" NAME="newconfigbutton" button.ONCLICK="createNewConfig()">
     
      <?php
         if($_SESSION['adminMode'])
         {
            echo '<INPUT TYPE=button VALUE="Modify Existing Item" NAME="modifyconfigbutton"/>';      
         }
         else
         {
            echo '<INPUT TYPE=button VALUE="Modify Existing Item" DISABLED="disabled" NAME="modifyconfigbutton" />';     
         }
      ?>
      <INPUT TYPE=button VALUE="Search" NAME="genericsearchbutton" ONCLICK="window.location='genericsearchlist.php';">
      </CENTER>
      <BR>
      <BR>
      <!-- create a hidden textbox for new config items -->
      <B><FONT SIZE=5>System  <INPUT NAME="newConfigText" TYPE="text" ID="systemtext" STYLE="display:none;"> <SELECT NAME="system" ID="systemselect" SIZE="1" ONCHANGE="setOptions(document.genericform.systemselect.options[document.genericform.systemselect.selectedIndex].value);"> 
      <OPTION VALUE="304315-701 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-701 SDC1-2')  == 0) echo "SELECTED";?>> 304315-701 SDC1-2 
      <OPTION VALUE="304315-702 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-702 SDC1-2')  == 0) echo "SELECTED";?>> 304315-702 SDC1-2   
      <OPTION VALUE="304315-703 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-703 SDC1-2')  == 0) echo "SELECTED";?>> 304315-703 SDC1-2 
      <OPTION VALUE="304315-704 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-704 SDC1-2')  == 0) echo "SELECTED";?>> 304315-704 SDC1-2 
      <OPTION VALUE="304315-705 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-705 SDC1-2')  == 0) echo "SELECTED";?>> 304315-705 SDC1-2 
      <OPTION VALUE="304315-706 SDC1-2"  <?php if(@strcmp($_POST['system'], '304315-706 SDC1-2')  == 0) echo "SELECTED";?>> 304315-706 SDC1-2 
      <OPTION VALUE="304316-701 P73 Kit" <?php if(@strcmp($_POST['system'], '304316-701 P73 Kit') == 0) echo "SELECTED";?>> 304316-701 P73 Kit
      <OPTION VALUE="304316-702 P73 Kit" <?php if(@strcmp($_POST['system'], '304316-702 P73 Kit') == 0) echo "SELECTED";?>> 304316-702 P73 Kit
      <OPTION VALUE="304316-703 P73 Kit" <?php if(@strcmp($_POST['system'], '304316-703 P73 Kit') == 0) echo "SELECTED";?>> 304316-703 P73 Kit
      <OPTION VALUE="304316-704 P73 Kit" <?php if(@strcmp($_POST['system'], '304316-704 P73 Kit') == 0) echo "SELECTED";?>> 304316-704 P73 Kit
      <OPTION VALUE="304317-701 MDR2-2"  <?php if(@strcmp($_POST['system'], '304317-701 MDR2-2')  == 0) echo "SELECTED";?>> 304317-701 MDR2-2 
      <OPTION VALUE="304317-702 MDR2-2"  <?php if(@strcmp($_POST['system'], '304317-702 MDR2-2')  == 0) echo "SELECTED";?>> 304317-702 MDR2-2 
      <OPTION VALUE="304318-701 CSD1-3"  <?php if(@strcmp($_POST['system'], '304318-701 CSD1-3')  == 0) echo "SELECTED";?>> 304318-701 CSD1-3 
      <OPTION VALUE="304318-702 CSD1-3"  <?php if(@strcmp($_POST['system'], '304318-702 CSD1-3')  == 0) echo "SELECTED";?>> 304318-702 CSD1-3 
      <OPTION VALUE="304318-703 CSD1-3"  <?php if(@strcmp($_POST['system'], '304318-703 CSD1-3')  == 0) echo "SELECTED";?>> 304318-703 CSD1-3 
      <OPTION VALUE="304319-701 CSD1-4"  <?php if(@strcmp($_POST['system'], '304319-701 CSD1-4')  == 0) echo "SELECTED";?>> 304319-701 CSD1-4 
      <OPTION VALUE="304319-702 CSD1-4"  <?php if(@strcmp($_POST['system'], '304319-702 CSD1-4')  == 0) echo "SELECTED";?>> 304319-702 CSD1-4 
      <OPTION VALUE="304319-703 CSD1-4"  <?php if(@strcmp($_POST['system'], '304319-703 CSD1-4')  == 0) echo "SELECTED";?>> 304319-703 CSD1-4 
      <OPTION VALUE="304320-701 MLS1-1"  <?php if(@strcmp($_POST['system'], '304320-701 MLS1-1')  == 0) echo "SELECTED";?>> 304320-701 MLS1-1 
      </SELECT></B></FONT>
      <BR>
      <BR>
      <!-- Items -->
      <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
      <TR>
      <BR>
    	<TD><B><FONT SIZE=2>Item 1</TD></B></FONT>
      </TR>
      <TR>
    	<TD ID="textfields"><FONT SIZE=2><SIZE=30>Description&nbsp;&nbsp;<INPUT TYPE="text" NAME="description" VALUE="" </FONT></SIZE>
    	<FONT SIZE=2><SIZE=30>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part Number <INPUT TYPE="text" NAME="partno" VALUE="<?php if(isset($_POST['partno'])) echo $_POST['partno'];?>" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }"><BR></TD></FONT></SIZE>
      </TR> 
    
      <!-- Wiring Harness -->
      <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
      <TR>
      <BR>
      <BR>
      <BR>
    	<TD><B><FONT SIZE=2>Wiring Harness 1</TD></B></FONT>
      </TR>
      <TR>
    	<TD ID="whtextfields"><FONT SIZE=2><SIZE=30>Description&nbsp;&nbsp;<INPUT TYPE="text" NAME="description" VALUE="" </FONT></SIZE>
    	<FONT SIZE=2><SIZE=30>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part Number <INPUT TYPE="text" NAME="partno" VALUE="<?php if(isset($_POST['pnofield'])) echo $_POST['pnofield'];?>" ONKEYDOWN="if (event.keyCode==9) { addNewWiringHarness(); }"><BR></TD></FONT></SIZE>
      </TR> 
      </TABLE>   
      <BR>
      <BR>
      <BR>
      
    <?php
      function init()
      {     
         if ($_SESSION['genericNewConfig'])
         { 
            echo '<INPUT TYPE=submit VALUE="Save"    NAME="generic_savebutton"   ONCLICK="verifySave()" />';
            echo '<INPUT TYPE=reset  VALUE="Cancel"  NAME="generic_cancelbutton" ONCLICK="verifyCancel()" />';
         }
         else 
         {
            echo '<INPUT TYPE=button VALUE="Save"   NAME="generic_savebutton"   DISABLED="disabled" />';  
            echo '<INPUT TYPE=button VALUE="Cancel" NAME="generic_cancelbutton" DISABLED="disabled" />';
         }
      }
    ?>
    
    </FORM>
    </BODY>	  
    
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    
      var numItems = 1; 		// Number of Items on page
      function addNewItem() 
      {
         // Increase the number of items
         numItems++;
    
         // Add the rows to the Inner HTML of our TD
         document.getElementById("textfields").innerHTML += '<B><FONT SIZE=2>Item '+numItems+'   <BR></B>'+
         'Description&nbsp;&nbsp;<INPUT TYPE="text" NAME="textfield2" VALUE=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
         'Part Number <INPUT TYPE="text" NAME="pnotextfield" VALUE="" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }"><BR>';
    
         <!--Set focus the textfield after the browser has a chance to add it-->
         <!--setTimeout('document.forms[0].elements["textbox'+numItems+'"].focus();',100);-->
      }
    
      var numWiringHarnesses = 1; 
      function addNewWiringHarness() 
      {
         // Increase the number of items
         numWiringHarnesses++;
    
         // Add the rows to the Inner HTML of our TD
         document.getElementById("whtextfields").innerHTML += '<B><FONT SIZE=2>Wiring Harness '+numWiringHarnesses+'   <BR></B> '+
        'Description&nbsp;&nbsp;<INPUT TYPE="text" NAME="textfield2" VALUE=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
        'Part Number <INPUT TYPE="text" NAME="pnotextfield" VALUE="" ONKEYDOWN="if (event.keyCode==9) { addNewWiringHarness(); }"><BR>';
    
         <!--Set focus the textfield after the browser has a chance to add it-->
         <!--setTimeout('document.forms[0].elements["textbox'+numWiringHarnesses+'"].focus();',100);-->
      }
    
      function createNewConfig()
      {      
         //window.location='systemconfig-generic.php';    
         document.getElementById('systemselect').style.display='none';
         document.getElementById('systemselect').value="";
         
         document.getElementById('systemtext').style.display='';
         document.getElementById('systemtext').focus();    
      
         </SCRIPT>
         </HEAD>
         <BODY>
         <FORM ACTION="" METHOD="post">
         <?php $_SESSION['genericNewConfig'] = true; ?>   
         <?init(); ?>   
         </FORM>
         </BODY>
         </HTML>
      }
      <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
      <HEAD>
      <HTML>
      function verifySave()
      {
         msg = "Are you sure you want to save this data?";
         //all we have to do is return the return value of the confirm() method
         return confirm(msg);
      }
    
      function verifyCancel()
      {
         msg = "Are you sure you want to cancel?";
         //all we have to do is return the return value of the confirm() method
         return confirm(msg);
      }
     
    </SCRIPT>
    </HEAD>
    </HTML>
    
    
    
    Code (markup):
     
    lost, Nov 17, 2005 IP
  9. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #29
    Start by fixing all your HTML errors. The document needs to be like this:

    DOCTYPE declaration here
    <html>
    <head>
    Script/metatags/style/title tags here
    </head> after this you can't have any more head tags
    <body>
    Here is where all the body goes
    </body>
    </html>

    You can't have more than one each of these tags.
    <html></html>
    <head></head>
    <body></body>
     
    exam, Nov 17, 2005 IP
  10. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #30
    I think i cleaned it up, however i keep getting an error on the </script> thats in the middle of the function, can i do that???
     
    lost, Nov 17, 2005 IP
  11. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #31
    Someone please help me, i'm need to call a php function within javascript code? how do i do this?? i'm doing this:

    
    
    <HEAD>  
    <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript">
    
      function createNewConfig()
      {   
         <?php 
         $_SESSION['genericNewConfig'] = true;  
         checkNewConfig();   
         ?>
         
         //window.location='systemconfig-generic.php';    
         document.getElementById('systemselect').style.display='none';
         document.getElementById('systemselect').value="";
         
         document.getElementById('systemtext').style.display='';
         document.getElementById('systemtext').focus();    
      }
    </SCRIPT>
    </HEAD>
    
    
    <BODY>
    <FORM ID="genericform" ACTION="systemconfig-generic.php" METHOD="post">
      <?php 
      function checkNewConfig()
      {     
         if ($_SESSION['genericNewConfig'])
         { 
            echo '<INPUT TYPE=submit VALUE="Save"    NAME="generic_savebutton"   ONCLICK="verifySave()" />';
            echo '<INPUT TYPE=reset  VALUE="Cancel"  NAME="generic_cancelbutton" ONCLICK="verifyCancel()" />';
         }
         else 
         {
            echo '<INPUT TYPE=button VALUE="Save"   NAME="generic_savebutton"   DISABLED="disabled" />';  
            echo '<INPUT TYPE=button VALUE="Cancel" NAME="generic_cancelbutton" DISABLED="disabled" />';
         }
      }
      ?>
      
    </FORM>
    </BODY>
    
    
    
    Code (markup):
     
    lost, Nov 18, 2005 IP
  12. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #32
    You can't call a php function from within javascript. What you can do, is have the *output* of a php function become part of your javascript.

    When your page is requested by someone's browser, server will look at the file and first evaluate and execute all php code. The output of that will be *only* HTML, Javascripte etc. That is what is sent to the browser.

    If you want some help, try expaining exactly what you want to accomplish with this and I can tell you how I would do it. I simply can't decipher what you're trying to achieve by looking at your code.
     
    exam, Nov 18, 2005 IP
  13. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #33
    Ok thanks Exam.
    I have a button called "CreateNewConfig" that when pressed will set the SESSION variable to true. It then needs to call the function checkStatus(), which determines the SESSION variable and if false, will disable the submit and cancel buttons, if true, will make them available. This checkStatus() method needs to be called more than once.
    Does this make sense? Enough information?

    Thanks in advance.
     
    lost, Nov 18, 2005 IP
  14. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #34
    What you have described are some of the steps to accomplishing a given task, but what is the overall goal you have? If you need to register users or something, but you have some special requirement, that is what you need to describe.
     
    exam, Nov 18, 2005 IP
  15. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #35
    My apologies.
    The form starts of with a defaulted selection box and disabled save/cancel buttons. If the user selects the newconfig button, they are able to create a new configuration item, which will change the select box to a text box and make all fields on the form writeable, and make the save/cancel buttons availble to submit the form.
     
    lost, Nov 18, 2005 IP