Friday, 15 April 2011

javascript - Choosing page depending on users choices -


I am trying to create a webpage where the user asked his name (textbox) and gender (radio button) on the front Page. It will then link to a new page depending on whether they are selected or not, if they are male or female, they will also need to display their name as entered in the text box.

So far my name is in the part that uses JavaScript, it is on the front page of the form given on the action form:

  // Uniforms of the form 'Tosubmit () {// get your value on the function text input var mytext = document.getElementById ("mytext"). Values; // store the above values ​​in localStorage localStorage.setItem ("mytext", mytext); Back true; }  

and it is on the other page:

  // call on the `Onload` event function in the body called init () {// Text input The retrieval value of which was stored in LocalStorage var mytext = localStorage.getItem ("mytext"); // Writing value in document document.getElementById ("name") InnerHTML = mytext; }  

The main problem is that it always directs to a single page. Can anyone tell me how I can solve this problem and add the option to select the user for my gender and the next page will depend on this choice?

Edit: This is my form

  & lt; Form class = "enter-name" name = "myform" onsubmit = "tosubmit ();" Action = "page1.html" & gt; & Lt; Input id = "mytext" type = "text" name = "data" placeholder = "enter name" maxlength = "12" & gt; Male: & lt; Input type = "radio" name = "gender" value = "male" /> gt; & Lt; Br / & gt; Women: & lt; Input type = "radio" name = "gender" value = "woman" /> gt; & Lt; Br / & gt; & Lt; Input id = "name-deposit" type = "submit" value = "" & gt; & Lt; / Form & gt; You can solve it with php - you can redirect form post to a handler. Based on the values ​​posted, the handler is in the same page in this case:  

  & lt ;? Php if (isset ($ _ POST ['name'], $ _POST ['gender'])) {$ page = ($ _POST ['gender'] == 'male')? 'Male page. Php ':' female page. Php '; Header ('location:' $ $ page '? Name =' $ _ post ['name']); Die (); }? & Gt; & Lt; Html & gt; & Lt; Head & gt; & Lt ;! - The main stuff here - & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form class = "enter-name" name = "myform" verb = "" method = "post" & gt; & Lt; Input id = "mytext" type = "text" name = "name" placeholder = "enter name" maxlength = "12" & gt; Male: & lt; Input type = "radio" name = "gender" value = "male" /> gt; & Lt; Br / & gt; Women: & lt; Input type = "radio" name = "gender" value = "woman" /> gt; & Lt; Br / & gt; & Lt; Input id = "name-deposit" type = "submit" value = "" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

in redirect to the page, you can use the name in php through the query string parameter:

   

No comments:

Post a Comment