...

View Full Version : Pls help me with JavaScript and PHP together...



joda
05-18-2009, 03:39 AM
Hi!
I have a big problem with this 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:



<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...

venegal
05-18-2009, 04:29 AM
Does the file E-mail_forma.php exist, and does it actually echo anything?

joda
05-18-2009, 04:55 AM
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...

rangana
05-18-2009, 05:00 AM
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.

joda
05-18-2009, 10:16 AM
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... :-(

rangana
05-18-2009, 12:23 PM
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.

venegal
05-18-2009, 12:23 PM
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.

oesxyl
05-18-2009, 12:23 PM
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:


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

joda
05-18-2009, 04:43 PM
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:


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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum