
October 22nd, 2012, 05:24 AM
|
|
|
Your syntax is correct, however you cannot assign a value to an element that does not yet exist. The document loads line by line, so when it reaches your Javascript the input has not yet been created and it will throw an error (Not likely to be seen). You can either move your script below the input element, not something I would personally do, or apply an event listen, as follows.
Javascript Code:
Original
- Javascript Code |
|
|
|
onload = startup; // When the document has finished loading, run the "startup" function. function startup() { document.getElementById('fname').value = 'rageedi'; }
Obviously if you are going to be calling this script from a click or form submission, then it will no longer be an issue.
|