SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error 405 when using post

    I'm a complete novice regarding javascript and I'm trying to use a piece of javascript to hide a page on my website. I am using the following script:
    Code:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    
    <html>
    
    <head>
    <title>(Type a title for your page here)</title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    
    <script language="javascript">
    
    function gonext(){
    location = form1.password.value+".html"
    }
    
    </script>
    
    </head>
    
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    Protected area.  Please enter password and click "go"<p>
    <form action="" name="form1" method="post"  onsubmit="gonext(); return false;">
    <input type=password name="password">
    <input type=submit value="go">
    </form>
    
    </body>
    
    </html>
    I have adapted and styled this form to make it invisible on this page:
    http://www.mereamdram.co.uk/understage.html

    It works fine in IE7 but Firefox returns an error 405
    Method Not Allowed
    The requested method POST is not allowed for the URL /understage.html.

    Apache/1.3.41 Server at www.mereamdram.co.uk Port 80
    How can I make it work for FF?

    The code works for both IE7 and FF on the site I copied the script from.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Am I right in assuming that you want to simply redirect to the location typed into the input? If so, the code on your page doesn't seem correct.

    Change the gonext function to:

    Code javascript:
    function gonext(){
                window.location = form1.password.value+".html"
            }


  3. #3
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Gavin, that is the basic requirement, it's for a simple security measure to allow access to minutes of meetings etc. stuff that isn't of itself secret, the meetings are open, but the 'client' doesn't want it readily accessible to all and sundry.

    As far as your suggestion is concerned, unfortunately I get the same result, works Ok in IE7 but I still get the error message in FireFox.

    When I said I was a novice, what I meant was, I copy snippets of code from others, I haven't got a clue what they mean

    Googling the problem suggests I need to implement dopost, unfortunately I can't find instructions (that I can understand) on how to do this.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.. What server side technology are you using? That may open a few possibilities for a different solution.

    Gav


  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    Ok.. What server side technology are you using?
    I'm guessing none.

    The problem seems to be, that you have a form, which is set to POST on submit. You then have an eventhandler connected to onsubmit of said form. In the eventhandler, you change the page location. Apparently in Firefox, the form continues its submit, while in IE, the location changes before the form is submitted and this causes the submit to stop. The "return false" in onsubmit should have stopped the event, but for some reason it doesn't work. Possibly because the eventhandler fails. Try this, to see what's going wrong:

    Code:
    function gonext(){
      try {
        window.location = form1.password.value+".html"
      } catch (err) {
        alert(err.message);
      }
    }
    My guess is that you can't use form1.password to access the form field in Firefox. Try assigning an id to the field and retrieve it with document.getElementById

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Gavin, kyberfabrikken is correct, as far as I'm aware I'm not personally doing anything server side. Nor do I know what's available, I'm using some spare space that a friend has on his account and I'm loathe to make enquiries of him as he's not charging me anything. Not an ideal situation I know, but these are small charity sites and anything that will reduce the costs is appreciated.

    As for the snippet of code I've included it on the page and it still works Ok in IE7 but FF now gives an error 'Form1 is not defined.'

    If it helps, I'm using 'frontstage' as my 'password' hoping to be taken to that page.

    I did say I was a complete novice, how would I include the 'document.getElementById' in the code.

    I'm assuming you also want me to assign an id to
    Code:
    <FORM name=form1 onsubmit="gonext(); return false;" action="" method=post>
    Thus:
    Code:
    <FORM id=somename name=form1 onsubmit="gonext(); return false;" action="" method=post>

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK. Assign an id attribute to the field, you want to access. In this case "password". Then fetch it in javascript, using document.getElementById. This is the correct way to access the DOM (document object model) from javascript, and should work on any browser:
    HTML Code:
    <input type="password" name="password" id="password" />
    and:
    Code:
    function gonext(){
      window.location = document.getElementById("password").value + ".html";
    }

  8. #8
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that kyberfabrikken, no luck I'm afraid it doesn't work for either IE7 or FF now.

    Unless of course I've done something particularly stupid.

    http://www.mereamdram.co.uk/understage.html to see the result.
    Code:
    <SCRIPT language=javascript>
    function gonext(){
      window.location = document.getElementById("password").value + ".html";
    }
    
    
    </SCRIPT>
    HTML Code:
    <div>
    	<!-- header content goes here -->
    	<a href="frontstage.html" title="Link to Front of Stage">
    			 <img src="images/mads4.gif" alt="MADS logo" />
    	</a>
    	<p>You will need a torch to have a look under here.</p>
    	<p>Click on the M.A.D.S. logo to return to the Front of Stage</p>
    	<input type="password" name="password" id="password" />
    </div>
    [

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a submit-button for your form. Otherwise, you can't submit the form in Firefox, and the event will never trigger.

  10. #10
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, does that mean re-installing the other script and html code?

    I may not get back too quickly, my builders have arrived and I'm up to my ears in rubble.

  11. #11
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SRD View Post
    Hi, does that mean re-installing the other script and html code?
    No, you just need to add a submit-button, as you had in your first example.

  12. #12
    SitePoint Zealot
    Join Date
    Sep 2007
    Location
    Wiltshire, UK.
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks kyberfabrikken, that seems to have cracked it.


Bookmarks

Posting Permissions

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