Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried this code to pass the value of $i to the script .. but it is not working
HTML
<html>
<head>
    <link rel="stylesheet" type="text/css" href="Styles\style.css"/>
    <title>iFound</title>
</head>
<body dir="rtl">
<div id="MainDiv">
    <div id="Headin"></div>
    <div id="Nav"></div>
    <?php
    for($i=0;$i<10;$i++)
    {
        echo "<div class=\"divs\"><div class=\"indivs\"></div><div class=\"intxtdivs\"></div></div>";
    }
    echo "<script type='text/javascript' language='javascript'>
            var a = 5;
            a = '<?php echo $i;?>';
            document.write(a);
          </script>"
    ?>
</div>
</body>
</html>


What I have tried:

a = ;

a = "";
Posted
Updated 10-Sep-16 15:27pm

To start with, you've a mess of single and double quotes. For example, you have:
PHP
echo "<script type='text/javascript' language="'javascript'">


This will print
JavaScript
<script type="text/javascript" language="
Then it will hit 'javascript' (with the single quotes and not context. An error!!!
afterwards it will start at
JavaScript
"> .......

You've got to get control of your single and double quotes. Your echo'd javascript is 'broken'. Also, the "language='javascript" is not even needed for anything - at least I've never used it like you have!

You should go over your entire code for the over-use and misuse of single and double quotes.
 
Share this answer
 
v2
Comments
Salah Abualrob 11-Sep-16 15:35pm    
i tried this
<pre lang="PHP">
echo "<script type=\"text/javascript\">
document.getElementById('MainDiv').style.length = 500;
var i = \"<!--?php echo $i;?-->\"
</script>";
?>
</pre>

but still not working .. i has no value and nothing change to length
echo $i; inside var i
W Balboos, GHB 12-Sep-16 6:58am    
You should look at the page source of your page and see what exactly it is your page looks like (to the browser). Also, there are not garbage tags,like <prelang="PHP"> when you start a php block. Just open it with <?php and close it with ?>" everything in between MUST be php and will be treated like php.

Perhaps a tutorial will help: http://www.w3schools.com/php/default.asp . You may wish to run through their javascript tutorial, as well.
Try the below code hope this helps
HTML
<html>
<head>
    <link rel="stylesheet" type="text/css" href="Styles\style.css"/>
    <title>iFound</title>
</head>
<body dir="rtl">
<div id="MainDiv">
    <div id="Headin"></div>
    <div id="Nav"></div>
    <?php
    for($i=0;$i<10;$i++)
    {
        echo "<div class=\"divs\"><div class=\"indivs\"></div><div class=\"intxtdivs\"></div></div>";
    }
    echo "<script type='text/javascript'>
            var a = 5;
            a = '".$i."';
            document.write(a);
          </script>";
    ?>
</div>
</body>
</html>
 
Share this answer
 
v4
Comments
W Balboos, GHB 10-Sep-16 21:19pm    
Your posting of an answer appears to be a total wreck. You have php functionality, such as 'ECHO' and you never have a php Opening tag . In matter of fact, you need more than one set. Did you test this code before posting it ?
ChauhanAjay 11-Sep-16 18:14pm    
I have tested the code and and then pasted it here I don't know why it missed the php tag. Anyway I have added the php tag.
W Balboos, GHB 12-Sep-16 7:02am    
It's always a good idea to check your post after you post it . . . especially if it has, for example, tags in it. They may be modified by the system and not show what you expected. I did that, fixing my own post, as recently as two minutes ago!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900