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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    Most of the time - internet
    Posts
    85
    Thanks
    0
    Thanked 1 Time in 1 Post

    Function parameters, within function parameters

    Hi,

    I am making a function that executes code as AJAX readyState's are returned...

    If readyState = 3 then I running code through eval but I want to be able to run functions with parameters, within the parameter that is evetually executed by the eval

    Heres abit of pseudo code of what I am talking about
    Code:
    function receiveRequest(whileLoading, whenDone) {
          // AJAX stuff... blah... blah... blah...
          if request is being processed:
              eval(whileLoading)
          if request is done:
              eval(whenDone)
    }
    
    // When a button is clicked:
    onClick="receiveRequest('alert('loading')', 'alert('finished AJAX request')')"
    But this doesn't work because I am escaping the first parameter of 'receiveRequest' in the alert()
    but if I use double quote (") I will be escaping the event handler

    Is there anyway to get around this / or a better way to fix it?


    I haven't used Javascript in agggeeesss and I can barely remember anything anymore - PHP <3

    Thanks in advanced.

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    You might be able to solve it by escaping the inner single-quotes
    Code:
    onClick="receiveRequest('alert(\'loading\')', 'alert(\'finished AJAX request\')')"

  • #3
    New Coder
    Join Date
    Jul 2009
    Location
    Most of the time - internet
    Posts
    85
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for your help - it worked =)


  •  

    Posting Permissions

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