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.

including php variable in javascript function

Discussion in 'JavaScript' started by bananalive, Jun 27, 2008.

  1. #1
    how can i include a php variable (eg. $textstring) into javascript function

    Here's the code:

    <script>
    function insertText() {
    var textstring = "test string";
    document.getElementById ("{$editorid}_iframe").contentWindow.document.body.innerHTML += textstring;
    document.getElementById('vB_Editor_001_textarea').value += textstring;
    }
    </script>
    Code (markup):
    <a href="javascript:;" onClick="insertText()">test</a>
    HTML:
    I just want to insert $textstring instead of var textstring ($textstring which is identified in php script)

    Thanks in advance,
     
    bananalive, Jun 27, 2008 IP
  2. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var textstring = "<?=$textstring ?>";
     
    koolman, Jun 27, 2008 IP
  3. bananalive

    bananalive Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for your help
     
    bananalive, Jun 27, 2008 IP
  4. bananalive

    bananalive Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    When $textstring is more than 1 line it doesnt work, is there a way around this?

    using \n doesnt work for iframes and it would make the line too long :(

    EDIT: Found solution :D
     
    bananalive, Jun 27, 2008 IP