Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

    Pls help me with JavaScript and PHP together...

    Hi!
    I have a big problem with this code:

    Code:
    <body>
    <script type="text/javascript">
    <!--
    var dugme1 = 'Ovo je prvi div';
    var dugme2 = '<?php include("E-mail_forma.php"); ?>';
    var dugme3 = 'Ovo je treci div';
    //-->
    </script>
    
    <div id="neki_div">
    </div>
    
    <div>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme1;">Prvi div</a>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme2;">Drugi div</a>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme3;">Treci div</a>
    </div>
    </body>
    This code didn't work for me,
    but if I use this one:

    Code:
    <body>
    <script type="text/javascript">
    <!--
    var dugme1 = 'Ovo je prvi div';
    var dugme2 = '<?php echo "Hello world!"; ?>';
    var dugme3 = 'Ovo je treci div';
    //-->
    </script>
    
    <div id="neki_div">
    </div>
    
    <div>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme1;">Prvi div</a>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme2;">Drugi div</a>
    <a href="#" onclick="document.getElementById('neki_div').innerHTML = dugme3;">Treci div</a>
    </div>
    </body>
    This works fine.

    The difference is only in the line where I try to make an INCLUDE option and where I print out some word with the ECHO command.
    I mean if I can use the ECHO command why can I not use the INCLUDE command?

    If I use the same PhP script outside the JavaScript it works fine to...
    Can somebody help me how to make an include with the above code?

    Thanks a lot...
    Last edited by joda; 05-18-2009 at 04:42 AM.

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Does the file E-mail_forma.php exist, and does it actually echo anything?

  • #3
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts
    Yes, the E-mail_forma.php exist and the echo print out the Hello world! sting's...

    The problem is,it's look like does with javascript I can't use the include command...

    You can try it to...
    If I use the first code and I click on "Prvi div" or "Drugi div" or "Treci div" nothing is doing but with the second code it work's...

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    There is really no problem on having "include()" inside the JS file.

    Since you can view the contents of the include file when parsed, check if there are issues from the parsed file.

    My best bet is that you are having quotes inside the include file, which (prematurely) terminates the script.

    It would help if you could provide a link to the offending page.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts
    Here is an active link to the source page www.code-elektronic.com/index2.php
    I modified into english language...

    I can see what is happening but I don't know how to solve my problem... :-(

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Just as I thought.

    As firebug reports, there's an unterminated string literal.

    In JS, a new-line is considered an end of statement, so you'd better place all of your markup from the include file in one line, instead of formatting it line-per-line.

    Hope that makes sense.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #7
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Please post the code of the file index2.php. It obviously doesn't just echo out a string, but knits together a whole HTML document.

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by joda View Post
    Here is an active link to the source page www.code-elektronic.com/index2.php
    I modified into english language...

    I can see what is happening but I don't know how to solve my problem... :-(
    maybe don't work because you include a full html document inside a div:
    Code:
    var button2 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Some page...</title>
    </head>
    
    <body>
    <p>Command 2 pressed</p>
    </body>
    </html>
    ';
    best regards

  • #9
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

    Cool

    Quote Originally Posted by rangana View Post
    Just as I thought.

    As firebug reports, there's an unterminated string literal.

    In JS, a new-line is considered an end of statement, so you'd better place all of your markup from the include file in one line, instead of formatting it line-per-line.

    Hope that makes sense.
    Is it not possible in java script to make a new line but the content should stay in one line in a variable? like in visual studio ?

    If in Visual Studio is your one line code to long you can brake in two or more line bat it not affect the sens of the code. Here is an examle in Visual Basic 6.0 how it work:

    Code:
    dim A as string
    A = "this is a very long text an we have no more space to put it on the screen_
    and I used the underline sign to brake this very long text into two_
    or more lines but the sense of the varioable A is just one line content..."
    is this not possible to do in java script?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •