0

I am creating a form in Html and I want to return the data entered by the user on another page of an Html. I don't want to go through the client-server coding. Just a simple Html page with the data after clicking Submit button. I am new to Html so just learning as you can see I have written an Html file name in the action attribute of the form. This is not working. Kindly reply, I cannot find the answer anywhere else. I am open to javascript.

<form action="formData.html" method="POST">

<table width="70%"  cellpadding="8"> 
 <tr>      
     <td width="40%">First Name:</td>         
     <td> <input type="text" name="first_name" /></td>
 </tr>
 <tr>
     <td>Middle Name:</td> 
     <td><input type="text" name="middle_name" /></td>
 </tr>
 <tr>
     <td>Last Name:</td>
     <td colspan="2"><input type="text" name="last_name" /></td>
 </tr>
 <tr>    
     <td>Gender :</td>
     <td width="30%"><input type="radio" name="gender" />Male</td>
     <td width="50%"><input type="radio" name="gender" />Female</td>
 </tr>
 </table>
 <input type="submit" value="submit" />
 </form>
Manish
  • 1
  • The page where the data I want to be returned should be an HTML page. – Manish Apr 10 '14 at 10:21
  • is the other html page on the same domain @manish – JF it Apr 10 '14 at 10:22
  • Yes, the other page is in the same folder within same Project.-@JFit – Manish Apr 10 '14 at 10:47
  • so when you hit submit, it goes to 2nd page? and you want the inputs available for use on the other page? @manish – JF it Apr 10 '14 at 11:09
  • Yes, @JFit it goes to the 2nd Html page where I want. But the Input data is not displaying on the page. If you have an ans. kindly reply – Manish Apr 10 '14 at 11:21
  • Yes there are a number of ways to persist data between pages.. The easiest I reckon is probally Querystrings. so on the submit of the button you'd be calling the url of the 2nd page and supplying the values at the end like window.location = "/secondpage?value1=a&value2=b" – JF it Apr 10 '14 at 11:25

1 Answers1

0

You can try to save it in the url (e.g. http://example.com/sendto.html?abc=sb&def=sth) and then use js to read it, etc.

A code that is needed to get the variable is this :

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

@Copyright jolly.exe from question How can I get query string values in JavaScript?

Codepen Example : http://codepen.io/jamiechoi/pen/tmphb?foo=sometext

Community
  • 1
  • 1
Jamie
  • 1,096
  • 2
  • 19
  • 38
  • Yea, @Jamie I can return the data in the url of another Html file through GET method. But I don't know how to retrieve it on the page, like with the help of js.- – Manish Apr 10 '14 at 10:55
  • Let me add example to my answer - sorry for not including answer, @Manish. – Jamie Apr 10 '14 at 12:16