Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  103] [ 4]  / answers: 1 / hits: 39524  / 12 Years ago, tue, october 16, 2012, 12:00:00

I have the following form which is getting pre populated with values on load. I want to have empty input boxes on load using Javascript. However I do not have access to the <body> tag so <body onload= will not work here. Is there any other way to clear the form fields on load?



<form method=POST action=>
<input name=username id=user value= /><br />
<input name=pwd id=pass value= />
<input type=submit value=Go />
</form>

More From » dom

 Answers
16

You can use window.onload instead.



function init() {
// Clear forms here
document.getElementById(user).value = ;
}
window.onload = init;


You could also use one of the nice wrappers for doing this in JQuery, Dojo, or you favorite Javascript library. In JQuery it would be,



$(document).ready(init) 

[#82523] Monday, October 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kareem

Total Points: 733
Total Questions: 110
Total Answers: 102

Location: Bermuda
Member since Thu, Apr 20, 2023
1 Year ago
;