Tuesday, April 7, 2020

Sending form data from one HTML file to another HTML file

first.html

JavaScript:

// 'document.formName.textFieldName.value ' gives the value entered in the text field of the form

function send(){ localStorage["aadhaar"]= document.registration.naadhaar.value;}

html:

<form name="registration" method='get' id='1' action='second.html' onsubmit='send()'>
<input type='text' id='aadhaar' name='naadhaar' placeholder="Aadhaar number...">
<input type="submit" value='submit'>
</form>

second.html

javaScript:

function data(){ var aadhaar=localStorage.getItem("aadhaar"); document.getElementById('aadhaar').innerHTML=aadhaar;}

html:

<body onload="showDate(), data();">
Aadhaar number = <span id="aadhaar" ></span>

</body>

Remember: A javascript code is never executed unless it is inside a function which is triggered by an event like button click, selectiion, onload etc.

No comments:

Post a Comment

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...