I create these code in my web application
<script type="text/javascript">
document.getElementById('articleTitle').value = "Ehsan" ;
</script>`
but in result my input has no value
my input is:
<input id="articleTitle" name="articleTitle" class="input-xxlarge"
type="text" placeholder="title">
my javascript code is above the html code
You need to make sure the element exists before you try to retrieve it. If your
scriptis above theinputin the HTML source, for instance, the element won’t exist when the script runs.You can either move your
scripttag underneath theinput, which will work, or use a “DOM ready” event of some kind. Putting thescripttag at the end of thebodyelement is recommend by the YUI team and others recommend just ensuring the script is below the element it works with.