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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variables in echo statement

    Hi,

    I try the following PHP statements generating a button in a table cell:


    echo '<td><button onclick="GetInfo($model)">'.$model.'<button></td>';

    echo '<td><button onclick="GetInfo('.$model.')">'.$model.'<button></td>';

    The button displays a model number on the button and passes the model number to the javascript function when being clicked.

    The test results indicate neither is right. Can you please tell me the right way for this statement?

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    would help to see more code but, try that, add the

    PHP Code:
    <?php ?>

    <td><button onclick="GetInfo(<?=$model;?>)"><?=$model;?><button></td>

    <?php ?>
    Last edited by seco; 09-22-2009 at 08:53 AM.

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    echo ''; => hello mr PHP, whatever you do, don't process this, just print it as it is.
    echo ""; => hello mr PHP, process everything in side me please!

    PHP Code:
    echo "<td><button onclick=\"GetInfo(".$model.")\">".$model."<button></td>";
    echo 
    "<td><button onclick=\"GetInfo(".$model.")\">".$model."<button></td>";
    or
    echo 
    "<td><button onclick=\"GetInfo($model)\">$model<button></td>";
    echo 
    "<td><button onclick=\"GetInfo($model)\">$model<button></td>";
    or
    echo 
    "<td><button onclick=\"GetInfo({$model})\">{$model}<button></td>";
    echo 
    "<td><button onclick=\"GetInfo({$model})\">{$model}<button></td>"
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    not sute what this is for tho:

    PHP Code:
    ".$model."<button></td>"; 
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    Quote Originally Posted by seco View Post
    would help to see more code but, try that, add the

    PHP Code:
    <?php ?>

    <td><button onclick="GetInfo(<?=$model;?>)"><?=$model;?><button></td>

    <?php ?>
    using short tags is a really really BAD habit stop it

    <?= <?php echo

    not all hosts support short tags and they can cause nightmare problems later on
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Or like
    PHP Code:
    echo "<td><button onclick=\"GetInfo('{$model}');\">{$model}<button></td>

        <td><button onclick=\"GetInfo('{$model}');\">$model<button></td>"

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The last <button>

    Oh, The last <button> should be </button>. Thanks for all thr great help.


    Warren


  •  

    Posting Permissions

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