How to get value in iframe from id element

heya

Can anybody give me a tip or somethig … I tried almost everthing …

facts:

I have html page with iframe.
parent form is … <form action=“<!$MG_REQ>” method=“post” id=“VNOS” name=“VNOS” …>
<iframe name=“ifrm” id=“ifrm” …>
iframe form is <form action=“<!$MG_REQ>” method=“post” id=“DELO” name=“DELO” … >

Now (i use iframe document ) … I want to check if some elements in iframe have any value.
for example … this field is in iframe
<input type=“text” class=“inbox” name=“VD” id=“VD” size=“08” maxlength=“03” value=“aa”/>

So what is the JS code to check the value?! If I try standard way like
“document.getElementById(“STRM”).value” … this is not working …

I know how to set value from main form to iframe “top.frames[‘ifrm’].document.getElementById(‘IZBR_STATUS’).value = box[box.selectedIndex].value;” … but If I am on iframe document I can’t check value when I submit iframe … it driving me nuts

It must be simple trick, but I can’t find the solution
Please share some help with me :wink:

thanx in advance


this snippet should help

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>
  <title></title>
</head>
<script language="JavaScript" type="text/javascript">
<!--
function whatever(iframeid,iframename){
 mmspobj=document.getElementById(iframeid);
 if (mmspobj.tagName=='IFRAME'){
  mmsiobj=window.frames[iframename].document.getElementId('myfield1ID').value;
 }
}
//-->
</script>
<body>

</body>

</html>


the iframe location must be of the same domain as the parent

heya, first thanx for helping me

well this is the example, how to get ID value, if I am on parent location and want to get value from iframe.

window.frames[iframename].document.getElementId(‘myfield1ID’).value;

But I need a script to check values of iframe elements when I submit iframe form.

function whatever(iframeid,iframename){
mmspobj=document.getElementById(iframeid);
if (mmspobj.tagName==‘IFRAME’){
mmsiobj=window.frames[iframename].document.getElementId(‘myfield1ID’).value;
}
}

the examle I posted will retrieve a field value from a field with id=iframename from the iframe with id=iframeid and name=iframeid and assign to variable mmsiobj
this value can be validated or assigned to a hidden field to be validated later with the balance if the form.

I may post an example later



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
<script language="JavaScript" type="text/javascript">
<!--
function whatever(iframeid,iframefield,target){
 mmspobj=document.getElementById(iframeid);
 if (mmspobj.tagName=='IFRAME'){
  myval=window.frames[iframeid].document.getElementById(iframefield).value;
 }
 document.getElementById(target).value=myval;
}
//-->
</script>
</head>

<body>
<input id="joe" size="10" disabled="disabled" ><input type="button" name="" value="Get IF Value from 1st IF Field" onclick="whatever('fred','tom','joe');" ><br>
<input id="joe1" size="10" disabled="disabled" >Auto Complete from 2nd IF Field<br>
<iframe name="fred" src="IF222.htm" width="500" height="200"></iframe>
</body>

</html>

IF222.htm

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”>


<html>

<head>
  <title></title>
<script language="JavaScript" type="text/javascript">
<!--

function PassBack(val,target){
 parent.document.getElementById(target).value=val;
}
//-->
</script></head>

<body>
<input id="tom" size="10"><br>
<input size="10" onkeyup="PassBack(this.value,'joe1');"><br>
</body>

</html>

heya vwphillips,

This is my example of what I want to do:

First main page:

<code>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title></title>
</head>
<body>

<p> I want to check a value of an input field (in iframe) if I submit iframe</p>
<iframe name=“fred” src=“my_iframe.html” width=“500” height=“200”></iframe>

</body>
</html>

</code>

Iframe page, where I want to test input value:

<code>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
http://www.w3.org/TR/html4/loose.dtd”>

<html>
<head>
<title></title>
<script language=“JavaScript” type=“text/javascript”>
<!–
function check_input_value()
{
alert( document.getElementId(“VD”).value);
}
//–>
</script>
</head>
<body>

<form action=“” method=“post” id=“DELO” name=“DELO” onsubmit=“check_input_value();”>
<input id=“VD” size=“10” value=“123”><br>
<input type=“submit” name=“submit” id=“submit” value=“submit”/>
</form>

</body>
</html>
</code>

So, on submit alert should tell me a value of input field in iframe …
Please take a look what I am missing here …

thanx

I now it’s working … the corect code is:
<script language=“JavaScript” type=“text/javascript”>
<!–
function check_input_value()
{
alert( document.getElementById(“DELO”).VD.value);
}
//–>
</script>

I didn’t get the value because I have had another input field with id=“VD” … lol … stupid … stupid … me (I should see it …)

sorry for bothering you all … sometimes help if you just tell somebody what are your problems :wink: