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

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...