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 9 of 9
  1. #1
    New Coder
    Join Date
    May 2015
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I Need help adding a javascript var to a form url

    Hi all,

    I need help adding a javascript var to a form url.

    So the form url is like:
    "url": "https://mypage/info/230",
    but I want to replace the number 230 with var MyNum like:
    var MyNum = 230;
    "url": "https://localhost/mypage/info/" + MyNum + "\"",
    but it doesn't seem to work
    Is there a better way to write it?


    Code:
    var settings = {
      "async": true,
      "url": "https://localhost/mypage/info/230",
      "method": "Post",
      more stuff.....
    }

  2. #2
    New Coder
    Join Date
    May 2015
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi - I could still use help with this... - Thanks

  3. #3
    New Coder
    Join Date
    May 2015
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    curious if there's a better place to ask this question

  4. #4
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,996
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    Code:
    <script>
    var str = "https://localhost/mypage/info/";
    var MyNum = 230;
    alert(str+MyNum);
    </script>
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  5. #5
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,345
    Thanks
    4
    Thanked 482 Times in 470 Posts
    Code:
    "url": "https://localhost/mypage/info/" + MyNum + "\"",
    is gibberish -- you don't need to force that escaped end quote...

    Code:
    "url": "https://localhost/mypage/info/" + MyNum,
    Should be all you need. No clue why you thought you needed that mess of quotes at the end, but the constructed URI would have ended up:

    Code:
    https://localhost/mypage/info/230"
    See that quote at the end? Pretty sure you don't want that.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com

  6. #6
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,996
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    yeah, that's what I said.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  7. #7
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    3,345
    Thanks
    4
    Thanked 482 Times in 470 Posts
    Quote Originally Posted by sunfighter View Post
    yeah, that's what I said.
    Not really -- or at least I wouldn't interpret it that way. You just posted some code but you didn't explain it, or WHERE the OP was messing up in their original. Changing that one line fixes it. Your snippet is the long from, but it doesn't actually tell them how/what/why/when/where. Ba ba ba babarbarino...
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture
    http://www.cutcodedown.com

  8. #8
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,996
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    Believe I answered he's question,
    I need help adding a javascript var to a form url.
    . Thought he was smart enough to apply it himself to the url, guess you didn't.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  9. #9
    New to the CF scene
    Join Date
    Apr 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll suggest you to just go through this you will find it informative https://bit.ly/2Fp4fxQ


 

Tags for this Thread

Posting Permissions

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