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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mixture of php and javascript ... link

    Hello, i am trying to get a link that calls a JS function im using

    $calltext = "<a onclick=myJSFunc('$someRandomphpVar'); return false href=mydoc.php>Click Me!!</a>";

    when you click the link, the page changes to mydoc.php, any ideas on how to stop this (the function of course works XD)

    thanks

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try:
    PHP Code:
    $calltext '<a onclick="myJSFunc(\''.addslashes($someRandomphpVar).'\'); return false;" href="mydoc.php">Click Me!!</a>'

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that gives a error ... error expected ';'

  • #4
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    then you either copy and pasted wrong or there is an error somewhere else in your code.

  • #5
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how can you c/p wrong? lol

  • #6
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the error says you're missing a semi-colon, maybe you missed that when you copy/pasted.

  • #7
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i didnt..i even c/p it a couple of times and its not my code..because it works when i used what id di form my firts post

  • #8
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    then post your code around the area the error comes from.

  • #9
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    .. the are is the code you gave me lol

  • #10
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jeromepelletier
    .. the are is the code you gave me lol
    copy and paste whatever it is so I can see the error.

  • #11
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $calltext = '<a onclick="myJSFunc(\''.addslashes($someRandomphpVar).'\'); return false;" href="mydoc.php">Click Me!!</a>'; ....

  • #12
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and if you comment it out you don't receive the error?

  • #13
    Regular Coder
    Join Date
    Jul 2005
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nope, page works fine once i take that out

  • #14
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if this doesn't work then I give up, this shouldn't be so complicated:
    PHP Code:
    $calltext "<a onclick=\"myJSFunc('".addslashes($someRandomphpVar)."'); return false;\" href=\"mydoc.php\">Click Me!!</a>"

  • #15
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    There was nothing wrong with the code you first posted...


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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