Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic value from a form inside of iframe not changing

Posted on 2009-04-06
11
Medium Priority
?
221 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

610 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