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.

Is we can insert php in javascript?

Discussion in 'PHP' started by hulkrana, Jan 24, 2008.

  1. #1
    Is we can insert php in javascript?
     
    hulkrana, Jan 24, 2008 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Dont really get your question?

    Do you mean can you print php, and javascript together?

    If that was the quesiton then yes you can, i prefer to brake out of php and then just place the html/javascript in.
     
    HuggyStudios, Jan 24, 2008 IP
  3. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Based on what I understood, what he meant was if we can run a PHP code inside javascript.
     
    Dondon2d, Jan 24, 2008 IP
  4. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #4
    Ohh, if you place the script inside say a php file, then you can actually print php into it, would not work if it was a external one linked tho.
     
    HuggyStudios, Jan 24, 2008 IP
  5. hulkrana

    hulkrana Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    yes code is
    function update()
    {
    frm2.unt.value=frm2.box1.options[frm2.box1.selectedIndex].text;
    frm1.untcd.value=frm2.box1.value;
    frm1.vch_cd.value=frm2.box1.options[frm2.box1.selectedIndex].text;
    //alert(frm2.unt.value);
    frm2.submit();
    //alert(frm2.unt.value);
    rw=document.getElementById('tbls1').rows.length;
    var x=document.getElementById('tbls1').insertRow(rw);
    document.getElementById('tbls1').rules="rows";
    var w=x.insertCell(0);
    var y=x.insertCell(1);
    var z=x.insertCell(2);
    var a=x.insertCell(3);
    var p=x.insertCell(4);
    w.width="2%";
    y.width="30%";
    z.width="40%";
    p.width="5%";
    w.align="right";
    y.align="left";
    z.align="left";
    a.align="left";
    p.align="right";
    <?php
    $rt="select * from t_fa_voucher where vch_no='".$_POST['unt']."'";
    //echo "de".$rt;
    $rt1=pg_query($rt);
    while($rt2=pg_fetch_row($rt1))
    {
    ?>
    w.innerHTML="<?php echo $rt2[2];?>";
    y.innerHTML="<?php echo $rt2[2];?>";
    z.innerHTML="<?php echo $rt2[2];?>";
    a.innerHTML="<?php echo $rt2[2];?>";
    <?php
    }
    ?>
    }
    k here i needed to fetch the data from database inside js?
    could it be possible here?

    thx
     
    hulkrana, Jan 24, 2008 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    Yes you can just start the php like you have and enter in your php code to get the information. Just make sure you print it out in the correct format.
     
    HuggyStudios, Jan 24, 2008 IP
  7. hulkrana

    hulkrana Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    but i tried my best but its not getg the result.this function is defined inside javascript
     
    hulkrana, Jan 24, 2008 IP
  8. hulkrana

    hulkrana Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    yes frd it is working but data values are not stable in it.
     
    hulkrana, Jan 24, 2008 IP