Reputation: 529
I have following javascript in which I want assign value of str to hidden field "abc" in form "form". It produces value of str in alert box but when I try to assign that value to abc using "document.forms[form].abc.value=str;" Then throws following error...
Message: 'document.forms.form.abc' is null or not an object
Line: 140
Char: 5
Code: 0
The variable image_url contains one url which is dynamically generated such as http://localhist/local/..../1234.jpg
How Do I get rid on this...
<script language="JavaScript">
function imgurl()
{
var str=image_url;
alert("Image Stored @"+str);
document.forms["form"].abc.value=str;
//document.getElementById('url').innerHTML=str;
}
</script>
<form name="form">
<input type="button" value="URL" onclick="javascript:imgurl();">
</td><br>
<td valign=top>
<div id="upload_results" style="border:2px black"></div><br/>
<input type="hidden" name="abc" value="">
<br/><p id="url"/>
</td>
</tr>
</form>
Upvotes: 0
Views: 137
Reputation: 62573
Use ids.
<input type="hidden" id="abc" name="abc" value="">
JavaScript:
function imgurl() {
document.getElementById("abc").value = img_url;
}
Upvotes: 1