-1

I'm using this form I found :

<FORM METHOD="POST" ENCTYPE="x-www-form-urlencoded">
    <input type="text" id="Password"/>
    <input type="button" id="Access" onclick="document.location=Password.value" VALUE="Accès"/>
</FORM>

It works fine for what I want to do, but I would like to allow the command to be triggered by pressing enter too. I have read a solution using the submit type instead and also a solution adding

onkeydown="if (event.keyCode == 13) document.getElementById('Access').click()" in the text input.

Neither works so I don't know if I'm misusing them or if my document.location=Password.value cannot be used this way. If so, could you indicate me the simplest solution to replace it without using php or js file because I don't really understand that. This website will not be public so I don't really care about security or if it's not the right way to do.

EDIT : Considering the answer you gave me are not fully working (jlbruno's one does not work neither on enter or on click, riad's one only works on click), here is the full code of my page with riad's solution, please tell me if something could interfere

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
 <head>
  <title>JVPW Cloud - Le Nuage de la JVPW !</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" media="screen" type="text/css" title="Design" href="design.css" />
  <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
 </head>
 <body>
    <p><center><img src="logo.png" width="1000" height="400" /></center></p>
    <p><span style="font-family:Verdana"><b>Tout l'univers de la JVPW pour seulement 9.99 $</b></span></p>

    <h1>Bienvenue</h1>
    <p>Si vous disposez d'un early access gratuit, entrez le code ci-dessous et appuyez sur Accès (pas Entrée !)</p>

    <FORM METHOD="POST" ENCTYPE="x-www-form-urlencoded">
    <input type="text" id="Password" onkeydown="if (event.keyCode == 13) document.getElementById('Access').click()" />
    <input type="button" id="Access" onclick="window.location=document.getElementById('Password').value ;" VALUE="Accès"/>
    </FORM>
    </body>
    </html>
Jeff
  • 4,136
  • 23
  • 32
Krys3000
  • 3
  • 5
  • `Password.value` ? how this will work? – Riad Jan 09 '15 at 16:35
  • Hi, I'm using the text imput to redirect, when the button is clicked on, the user on mywebsite.com/valueofthetext/ :) I have no idea if it should work but it does – Krys3000 Jan 09 '15 at 16:37
  • Your updated code example seems to work ok here as well. Can you create a snippet here that doesn't work, or maybe on js fiddle? + @Riad – Jeff Jan 09 '15 at 17:42
  • Yes it does. But not on my website. I'm guessing my server is somehow preventing it to work, that's the only solution I can think about. – Krys3000 Jan 09 '15 at 17:45
  • @jlbruno: "seems to work ok here as well" ... so why reproduce error? Krys3000 is not understanding how JS is working. Krys3000 : put the full website url instead of password.value or try with valid URL. can't you see error in / application...? – Riad Jan 09 '15 at 17:55
  • If I replace it with a full URL, it works... on clicking. Still Enter does nothing. – Krys3000 Jan 09 '15 at 18:06
  • Here is a new information : I tried to upload the page on another server. Enter does not work too, BUT it says this : "The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource. " What does it means ? – Krys3000 Jan 09 '15 at 18:16
  • I've tried on several other webhost and it still doesn't work. Enter key does not trigger the access. I really have no idea why. Does someone has an idea about how to make a form (even if it's not the same) that works ? – Krys3000 Jan 21 '15 at 13:11

3 Answers3

1

I wouldn't recommend having inline event handlers, but that said I'll keep doing it for an example.

You should change your button to a submit button, and move your current onclick into an onsubmit on the form.

    <FORM METHOD="POST" ENCTYPE="x-www-form-urlencoded" onsubmit="document.location=Password.value">
        <input type="text" id="Password"/>
        <input type="submit" id="Access" VALUE="Accès"/>
    </FORM>
Jeff
  • 4,136
  • 23
  • 32
  • Thank you but for some reason, It doesn't work. Should I add something else somewhere to make it work ? – Krys3000 Jan 09 '15 at 17:01
  • I've edited it above to make it a code snippet, so if you run that, enter some text into the input field and hit enter, it seems to work...it redirects to what was entered into the field. – Jeff Jan 09 '15 at 17:04
  • Yes it does. But when I put that on my website and upload it, it does not work. Clicking doesn't work anymore with your code, also. The text field just becomes blank and nothing happens :( – Krys3000 Jan 09 '15 at 17:11
  • Now I'm confused. If it works here, but not your website, then you haven't given us all the information we need. – Jeff Jan 09 '15 at 17:15
  • What do you mean "clicking doesn't work anymore" with my code? When you click "run the code snippet" above? – Jeff Jan 09 '15 at 17:16
  • BTW, I'd recommend my solution instead of Riad's as your javascript will fire in mine no matter how the form is submitted. – Jeff Jan 09 '15 at 17:19
  • I meant that your code doesn't allow me to run the process by entering but also it doesn't allow me to run it by clicking the button, which worked with my code. I am a complete beginner so I really don't know if I haven't given you the information you need, so please tell me if you know what could be the problem :) – Krys3000 Jan 09 '15 at 17:22
  • When you click "run code snippet" above, does it work the way you want? Here on StackOverflow? – Jeff Jan 09 '15 at 17:23
  • Yes, it works fine on the snippet. Just not in my website. I understand it should just as Riad's solution should. So probably it is not a code problem, or at least not this part of the page's code. but I really don't see where the problem is :( – Krys3000 Jan 09 '15 at 17:27
0

You can try this.

<FORM METHOD="POST" ENCTYPE="x-www-form-urlencoded">
 <input type="text" id="Password" onkeydown="if (event.keyCode == 13) document.getElementById('Access').click()" />
 <input type="button" id="Access" onclick="doSubmitWork();" VALUE="Accès"/>
</FORM>

<script type="text/javascript">
    function doSubmitWork(){
        window.location = 'mywebsite.com/'+document.getElementById('Password').value ;
    }
</script>

JS FIDDLE DEMO

Riad
  • 3,822
  • 5
  • 28
  • 39
  • Thank you, but your solution works when the button is clicked, but still pressing Enter won't do anything – Krys3000 Jan 09 '15 at 17:00
  • did you see it on the js fiddle? i see it works... when you fill up the textbox and hit `enter` key. – Riad Jan 09 '15 at 17:02
  • I'm sorry it's the first time I'm using this fiddle, but I tried to put something in the result field and press enter and it 403'd – Krys3000 Jan 09 '15 at 17:07
  • yeah..it should because there is no `mywebsite.com` right? you may put `google.com` on the window.location = '' value – Riad Jan 09 '15 at 17:08
  • Indeed it does seem to work on the fiddle but when I put your code on my website, only the click works. Enter makes the field to go blank and nothing happens. – Krys3000 Jan 09 '15 at 17:14
  • put the code from jsfiddle to your website and change the variables as needed. it works on fiddle and it should work everywhere! – Riad Jan 09 '15 at 17:16
  • I know, but It's not. Considering jlbruno's solution should also work normally, I'm starting to think there is another problem. Do you see what can prevent this to work, if it's not a code problem ? – Krys3000 Jan 09 '15 at 17:26
  • I edited the post with the full code of my page and your solution so you can see better ; currently it perfectly works ON CLICK but still no entering. – Krys3000 Jan 09 '15 at 17:36
-1

I did the following and it works for me. I hope is helps you.

<form name="frm" method="post">
    <input type="password" name="psw">
    <input type="submit" value="Enter">
</form>
Jeff B
  • 8,572
  • 17
  • 61
  • 140