HTML works but javascript fails with href

Discussion in 'JavaScript' started by Alf Stockton, Jul 5, 2013.

  1. #1
    I have javascript as follows
    
    function newDoc()     {     window.location.href ="http://192.168.0.8/devit/logon.html";     }
    
    Code (markup):
    If I call this function from my javascript as follows
    
            newDoc();
    Code (markup):
    it fails but if called from HTML
    
    <input type="button" nanme="SelectButton" id="SelectButton" value="Login" onclick="newDoc()" height="50"/>
    
    Code (markup):
    it works.

    Please tell me what I am getting wrong.
     
    Alf Stockton, Jul 5, 2013 IP
  2. SE-Go

    SE-Go Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    I have several questions to be able to answer your question:
    1. What is the context of where you are calling this from when it doesn't work?
    2. What error message are you getting when it doesn't work?
    3. Have you tried running it with a debugger to follow the code through to where it gets the error? I recommend Chrome with the Javascript Console. It lets you see what is going on.
     
    SE-Go, Jul 5, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    4) why are you futzing around with buttons and scripting to do an anchors job?
     
    deathshadow, Jul 6, 2013 IP
  4. Alf Stockton

    Alf Stockton Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Alert() has helped me resolve this issue. Thanks for your input.
     
    Alf Stockton, Jul 6, 2013 IP