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 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    78
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question If else does not works properly

    Dear all,

    I have a Function, but only the 1st if statement works, the second not.



    <script>
    function formatURL()
    {
    var url = document.getElementsByName("URL")[0];
    url = url.value;
    if(url.substr(0,3) === "www")

    {
    url.value = "http://"+url;
    return;

    }
    else
    {
    url.value = "https://"+url;
    return;

    }


    url.value = url;

    }
    </script>

    Could an expert help me to fix this error?

    Thank you in advance

    Bob
    Last edited by BOBKUSPE; Oct 4th, 2018 at 03:06 AM.

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,538
    Thanks
    5
    Thanked 155 Times in 150 Posts
    Tell us what the Real problem is that you are trying to solve instead of your attempt at solving it.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  3. #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,844
    Thanks
    58
    Thanked 689 Times in 684 Posts
    Besides, I suspect that is java, not javascript. Insert funny saying about java not being javascript here.

  4. #4
    New Coder
    Join Date
    Dec 2008
    Posts
    78
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Sorry, I did a mistake. It is the correct code

  5. #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,844
    Thanks
    58
    Thanked 689 Times in 684 Posts
    JavaScript is case sensitive, so
    Code:
    document.getElementsByName("URL")[0];
    and
    Code:
    document.getElementsByName("url")[0];
    are not the same thing


 

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
  •