Solved

Dynamic value from a form inside of iframe not changing

Posted on 2009-04-06
11
216 Views
Last Modified: 2012-05-06
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
Comment
Question by:Dada44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
ID: 24076170
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
 

Author Comment

by:Dada44
ID: 24076325
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
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
ID: 24076393
Does it alert +myid+ or a number the first time?
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

Author Comment

by:Dada44
ID: 24076562
+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
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
ID: 24076611
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
 

Author Comment

by:Dada44
ID: 24076652
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
 
LVL 3

Accepted Solution

by:
QualitySoftwareDevelopment earned 500 total points
ID: 24076723
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
 

Author Comment

by:Dada44
ID: 24076991
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
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
ID: 24077053
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
 

Author Comment

by:Dada44
ID: 24077745
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
 

Author Closing Comment

by:Dada44
ID: 31566944
Thanks! you gave me a great tip!!
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question