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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to replace the div content onclick?

    Here is my script..
    This works perfectly if the call the variable $ssk in the html, but it is not working when i call the variable $cvb.

    Please help me out...

    <!-- php code start -->
    <?

    $cvb='<div id="flashcontent">
    <script type="text/javascript">
    var so = new SWFObject("player.swf", "sree", "635", "240", "9", "#E7E7E7");
    so.addVariable("p_list", "try.xml");
    so.addParam("allowFullScreen", "true");
    so.write("flashcontent");
    </script>
    </div> ';

    $ssk='SREE';

    ?>
    <!-- php code end -->


    <html>
    <head>
    <script type="text/javascript" src="swfobject.js"></script>
    <title>Change div content</title>

    <style>
    /* this is just to add color and look :-)*/
    div, a { padding:3px; margin:3px 3px 33px 3px; }
    #scriptVars1 { border:1px solid red; width:635px; height:240px; background-color:#EEE;}
    </style>

    <script>
    function changeDivContent( nameOfDiv, newContent )
    {
    var div = document.getElementById( nameOfDiv );
    if( div )
    {
    div.innerHTML = newContent;
    }
    }
    </script>

    </head>
    <body>
    <a href="#" onclick="changeDivContent( 'scriptVars1', '<? echo $ssk; ?>' )">Click here to change the content</a>

    <div id="scriptVars1">
    <br/><br/><br/><br/>
    This content should be replaced...
    </div>

    </body>
    </html>


    Any help from this forum would be really appreciated.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    because unlike php javascript does not allow multi-line literal strings...so, if u remove all the line breaks in $cvb and echo it out it should work fine
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    siva1117 (08-10-2008)

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    i tried it but it doesn't seems to work

    Hi i tried removing all the line breaks, i even tried the backslash method but nothing seems to work....

    all i need is to fire a JavaScript in the variable position... $cvb

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    it's because you used all those double qoutes you probably need something more like this because if you echo double quotes into into your function it will mess things up.
    PHP Code:
    $cvb="<div id='flashcontent'>
    <script type='text/javascript'>
    var so = new SWFObject('player.swf', 'sree', '635', '240', '9', '#E7E7E7');
    so.addVariable('p_list', 'try.xml');
    so.addParam('allowFullScreen', 'true');
    so.write('flashcontent');
    </script>
    </div> "

    Though if you're worried about semantics you could set $cvb to a JavaScript varible before


  •  

    Posting Permissions

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