INOH INOH - 6 months ago 8
Javascript Question

Input values into html form using javascript

I am having difficulty figuring out where i am going wrong. Ihave searched the internet for several hours with no luck. this is my situation. I am running a mobile device app, i am loading a form (locally) into iframe. iam then (onload) trying to insert values into my forms textbox. here is the codes

<iframe name="myframe"id="myframe"
src="file:///C:/Users/denise/Desktop/updateform.html"
width=480px height=400px frameborder=1></iframe>


and the javascript function

function imLoaded(){
var ifrm = document.getElementById('myframe');
var form = doc.getElementById('updateform');
form.document.getElementById("updateform").user.value = 'hello';
}

Answer

Try this

var iframe = document.getElementById('myframe');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
alert(innerDoc.getElementById("updateform").innerHTML);
alert(innerDoc.getElementById("updateform")["user"].value);

you can use innerDoc with getElementById to get any element of id

Hope this will help you.