Thursday, 15 May 2014

javascript - HTML form that links to different pages depending on what user enters? -


Can HTML be linked to different websites, which text does the user enter? In other words, I have a simple text form where users can enter text and then press submit. An example of what I'm hoping to do is, there's a way to set it so that if they enter "ABC" and press submit, then they will take them to Google, but if they enter "XYZ" then Takes them to Jehu? Yes, you can go, but you need JavaScript, here is a very useful example, which reminds us about the Web 1.0 script. The code sets a listener on the textfield (key), and whenever the change takes place, the function changes, which then evaluates the value in the field. If it matches 'XYZ', then it sets the form property of the URL for the URL where you want the form submission. In this particular case, the URL will be something that does not exist. It is now necessary that this is not a complete solution and you have to spend some time that the handler will have to work properly.

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Test & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "myform" & gt; & Lt; Input type = "text" id = "mytext" onkeyup = "changed ()" & gt; & Lt; / Form & gt; & Lt; Script type = "text / javascript" & gt; Function changed () {var v = document.getElementById ('mytext'). Values; If ("XYZ" === v) {var action = "http: //www.foobar.nothing/" + v; Document.getElementById ('myform'). Action = action; }} & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

No comments:

Post a Comment