Submit Your Article Forum Rules

Results 1 to 2 of 2

Thread: Javascript and php

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Posts
    216

    Javascript and php

    Hello there.

    I have set a javascript array a[], each array element holds a list of training centres i.e.

    a[0] = leeds-edinburgh-leeds-leeds.

    i want to split these centres into javascript variuables i.e.

    echo "<script>
    var aims_array = a[$i].split("-");
    </script>
    ";

    but for some unknown reaseon when i add this code to my .php script i get random 0's printed to the screen
    i.e.

    00000000000000000000
    00000000
    000000000000000
    00
    0000000000000
    000000

    i'm not printing anything to the screen so why should this happen?

    Thanks, Chris.

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Posts
    309
    echo "<script>
    var aims_array = a[$i].split("-");
    </script>
    ";

    Your problem is the use of double quotes in the echo statement as it encounters another set inside the holding quotes.

    Either escape the inner quotes ala split(\"-\"); or use single quotes around the echo ala
    echo '<script> var aims_array = a[$i].split("-"); </script>';

    Some things to be aware of using ' and " in php.
    Everything inside " " (double quotes) is parsed - echo " $some_variable " will output the value of $some_variable.

    Nothing inside ' ' (single quotes) is parsed - echo ' $some_variable ' will do just that, print the text $some_variable.

    Hope that helps.
    "I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
    "The secret to creativity is knowing how to hide your sources" - Albert Einstein.

Similar Threads

  1. JavaScript Uses
    By jimmy03 in forum Search Engine Optimization Forum
    Replies: 2
    Last Post: 05-26-2009, 02:50 PM
  2. AJAX and javascript calling javascript
    By krnl in forum Web Programming Discussion Forum
    Replies: 14
    Last Post: 11-18-2007, 10:00 AM
  3. Javascript + RSS + RSS = ?
    By ofoglada in forum Web Programming Discussion Forum
    Replies: 6
    Last Post: 02-05-2006, 05:33 AM
  4. XP SP2, IE and Javascript
    By ChrisBowd in forum Graphics & Design Discussion Forum
    Replies: 1
    Last Post: 08-26-2004, 07:23 AM
  5. JavaScript Help
    By Dragonsi in forum Web Programming Discussion Forum
    Replies: 12
    Last Post: 05-29-2004, 04:30 AM

Posting Permissions

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