504 users online (0 members and 504 guests)  

Thread: echo Javascript

  Results 1 to 2 of 2


  1. Replies: 0
  2. javascript in echo php    Forum: PHP Forum
    Replies: 2
  3. Javascript event inside echo statement    Forum: PHP Forum
    Replies: 2
  4. Javascript in php echo()    Forum: PHP Forum
    Replies: 6
  5. Replies: 5
  1. #1
    d1343's Avatar
    New User

    Join Date
    May 2009

    echo Javascript

    I have php script and it uses echo to print any thing out
    well my script prints out some link
    and I want to add javascript to make it fancy..

    my javascript includes following files
    js file
    css file
    img file
    and hyperlink

    Please Help Me
    Thank you
    if you don't understand please tell me I can try to explain better

  2. #2
    deliriousthunder's Avatar
    Junior Member

    Join Date
    Feb 2009

    Re: echo Javascript

    I could be completely misunderstanding you, because I don't really understand why you would be having a problem doing this.

    Just use a normal php echo statement, and make sure you escape any apostrophes that php would interpret as an end to the echo.

    Escape them by preceding them with a backslash. Example:

    <?php echo '<a href=\'somelink\'>sometext</a>'; ?>
    I don't see why the fact that your javascript references other files would be a problem, since that would all be 'echo'd to the browser. The browser will just treat it like any other (html) page that it would process.

    If you're having trouble including your script and the php $link variable, you just need to use a "period" (we call them full stops where I'm from) to concatenate the strings with the variable. Example:

    <?php echo 'sometext'.$link.'somemoretext'; ?>
    Sorry if that's just condescending, sometimes it's difficult to tell how much of a language people know when they are asking questions. Am I missing something?

    Alternatively, assuming you are building a webpage from a .php file. You could simply exit the php for a while, write your script, and then enter php again to echo the link. Like so:

    <?php you are in php here, so close by doing this: ?> Insert your script as you normally would here, and then enter php again to echo the link, like this: <?php echo $link; //then you can exit php like this: ?> then close all your tags and finish your script here, and you can enter php again like this: <?php ...
    Hope that helps anyway.

Tags for this Thread