Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Dynamic value from a form inside of iframe not changing

Dynamic value from a form inside of iframe not changing

Dear all,

pageone.htm has an iframe with  pagetwo.htm inside
pagetwo has a form with a hidden field that has a dynamic value.
I'm trying to get that value from pageone.htm using:
var myid = window.frames['myiframe'].document.forms['myform'].elements['page'].value;

This is working, but I just get the value that the field had when I did:
 setInterval('alert(GetValue())', 9000);
for the first time. All the alerts after the first one have the same value even when myid is changing in pagetwo.htm (tested alerting it in there).

Is it a problem of cache? how can I fix this??
I thought that by using  setInterval I would be checking for a fresh value every 9 seconds but what I get is the same old value every 9 seconds :(  Please help!

See the whole code below.
Thanks a lot in advance!
///// pageone.htm /////
 
<script type="text/javascript">
function GetValue() {
var myid = window.frames['myiframe'].document.forms['myform'].elements['page'].value;
return myid;
} 
</script>
 
  </head>
  <body>
 
<iframe id='myiframe' name='myiframe' width='1024' height='650px'src='pagetwo.htm'></iframe>
 
<script type='text/javascript' language='JavaScript'>
 setInterval('alert(GetValue())', 9000);
</script>
 
 
 
///// pagetwo.htm /////
 
<FORM NAME='myform' METHOD='LINK' ACTION='pageone.htm'>
<input id='page' name='page' type='hidden' value='"+myid+"'/>
</FORM>

Open in new window

0
Dada44
Asked:
Dada44
  • 6
  • 5
1 Solution
 
QualitySoftwareDevelopmentCommented:
Hey this works ... how do you define myid? if myid is a varible I think you can just set the value equal the varible
<FORM NAME='myform' METHOD='LINK' ACTION='pageone.htm'>
<input id='page' name='page' type='text' value='test' />
</FORM>

Open in new window

0
 
Dada44Author Commented:
QualitySoftwareDevelopment, thansk for answering, but sorry, I don't get want you mean.

The value of the hidden field is a dynamic variable that comes from a quite huge programing too big to post it in here, but as I said before, I used alert in pagetwo.htm to check if it changes and has another value (this value is always a numer) and it does, it is dynamic, it changes.

Where it does not change is in pageone.htm
In pageone.htm I always get the value that the field had when I check it for the first time..

Any ideas?
Thanks again!
0
 
QualitySoftwareDevelopmentCommented:
Does it alert +myid+ or a number the first time?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Dada44Author Commented:
+myid+ is always a number, a number that changes from time to time depeding on the humongous programming that I mention before.

The first time alert is +myid+ but when +myid+ changes the following alerts don't register the change, they keep on showing the first value of +myid+

Thanks again
0
 
QualitySoftwareDevelopmentCommented:
Ok, how does the myid change? is it asp/php (serverbased) or is it javascript or other clientbased way.

If you want it to change without reloading you need to set it clientbased (see below note 1).

If you reload the page you need to make sure the myid is set accordingly to the serverbased scripting (see note 2)
Note 1:
<script>
window.frames['myiframe'].document.forms['myform'].elements['page'].value=<the new value>;
</script>
 
Note 2:
E.g. for PHP:
<FORM NAME='myform' METHOD='LINK' ACTION='pageone.htm'>
<input id='page' name='page' type='hidden' value='<?php echo $myip;?>'/>
</FORM>

Open in new window

0
 
Dada44Author Commented:
I'm afraid I cannot use any server side language in pagetwo.htm... I can use  just javascript, jquery or ajax :((
Is there any other way?
Thanks a ton!

0
 
QualitySoftwareDevelopmentCommented:
Your problem is that you (i think) used the alert as in note 1?! You cannot use a javascript varible in a input tag like note 2. Therefore you need to add the new value to the input using note 3. Otherwise you should retrive the myid from the actual source instead, if that is a javascriptvarible.

Note 1: 
alert(myid);
 
Note 2:
<input id='page' name='page' type='hidden' value='"+myid+"'/>
 
Note 3:
<script>
window.frames['myiframe'].document.forms['myform'].elements['page'].value=<the new value>;
</script>

Open in new window

0
 
Dada44Author Commented:
Gee, sorry I don't get you. It is probably because I named two different variables with the same name. Sorry!!!! Please see again the code below.

I did alert (changingValue) in pagetwo.htm and this is ok, this changes it's fine.
It's myid in pageone.htm the one that when I do:
 setInterval('alert(GetValue())', 9000);
Shows the same value all the time, even when changingValue has changed and the alert in pagetwo.htm is showing it.

Sorry again, and thanks!
///// pageone.htm /////
 
<script type="text/javascript">
function GetValue() {
var myid = window.frames['myiframe'].document.forms['myform'].elements['page'].value;
return myid;
} 
</script>
 
  </head>
  <body>
 
<iframe id='myiframe' name='myiframe' width='1024' height='650px'src='pagetwo.htm'></iframe>
 
<script type='text/javascript' language='JavaScript'>
 setInterval('alert(GetValue())', 9000);
</script>
 
 
 
///// pagetwo.htm /////
 
<FORM NAME='myform' METHOD='LINK' ACTION='pageone.htm'>
<input id='page' name='page' type='hidden' value='"+changingValue+"'/>
</FORM>

Open in new window

0
 
QualitySoftwareDevelopmentCommented:
you cannot use a javascript varible in the <input> tag

therefore the value of the input will nopt change.

but if you have the changingvalue from somewhere else, then why not use that in pageone.htm?!
0
 
Dada44Author Commented:
That would great, but I'm afraid  I cannot do it (or I don't know how to).
pagetwo.htm is not a simple htm page as I put it here to make it easier to understand, it is a full webpage with js files and the variable is comming from one of this js files.

I've tried calling the js where the variable is  in pageone.htm with    
<script type="text/javascript" src="myjsfile.js"></script>
And then doing something like:
var f;
f = myfucntion();
alert (f);

Being myfucntion the function where changingValue is in the js file.
But I get a "myfunction() is not defined error"..  Maybe I'm doing this wrong??

Thanks once again
0
 
Dada44Author Commented:
Thanks! you gave me a great tip!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now