Solved

Dynamic value from a form inside of iframe not changing

Posted on 2009-04-06
11
209 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
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:QualitySoftwareDevelopment
Comment Utility
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
Comment Utility
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
Comment Utility
Does it alert +myid+ or a number the first time?
0
 

Author Comment

by:Dada44
Comment Utility
+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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Dada44
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks! you gave me a great tip!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now