473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javscript - setting form field in an iframe

Bob
I'm a total newbie at Javascript, but a programmer for over 20 years...
so, my plans may be bigger than they are possible.

I'm trying to set with Javascript the value of a form field... easy
enough, right?

e.g. this successfully sets the local form's field:

document.thetes tform.mycity.va lue='paris';


however, I'm not sure how to do the same for a form that's within an
iframe, e.g. (consider that the remote url at example.com has 2 forms in
it; the 2nd frame contains a field called 'city' that I want to set):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1">
<SCRIPT LANGUAGE="JavaS cript" type="text/javascript">
<!--
function setfields()
{
document.theifr ame.document.fo rms[1].city.value='pa ris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#fffff f">
<form action="test.vs p" method="get" name="thetestfo rm"
enctype="applic ation/x-www-form-urlencoded">
<p><img src="clickme.gi f" alt="" width="90" height="65" border="0"
onclick="setfie lds()"></p>
<input type="text" name="mycity" size="24">
<input type="submit" name="submit">
</form>
<IFRAME name="theiframe "
SRC="http://www.example.com/cityinfo.html" width="95%" height="90%"
scrolling="auto " frameborder="1" >
</IFRAME>

</body>
</html>


this line doesn't seem to kick:

document.theifr ame.document.fo rms[1].city.value='pa ris';

unfortunately, the form on the example.com site does not have a name for
referencing, so I have to reference it as forms[1]... I understand that
this might make the form read only... is there a way to reference it
that's not read only? (or am I off base in my diagnostic?)

the example.com is not a site that I have any control over... gotta work
with what I gots.
thanks much, javascript gurus and galus.
B.
Jul 23 '05 #1
3 2610
It could be a security issue, copy all the code and IFRAMES to you local
machine and then retry.

Bob wrote:
I'm a total newbie at Javascript, but a programmer for over 20 years...
so, my plans may be bigger than they are possible.

I'm trying to set with Javascript the value of a form field... easy
enough, right?

e.g. this successfully sets the local form's field:

document.thetes tform.mycity.va lue='paris';

however, I'm not sure how to do the same for a form that's within an
iframe, e.g. (consider that the remote url at example.com has 2 forms in
it; the 2nd frame contains a field called 'city' that I want to set):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1">
<SCRIPT LANGUAGE="JavaS cript" type="text/javascript">
<!--
function setfields()
{
document.theifr ame.document.fo rms[1].city.value='pa ris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#fffff f">
<form action="test.vs p" method="get" name="thetestfo rm"
enctype="applic ation/x-www-form-urlencoded">
<p><img src="clickme.gi f" alt="" width="90" height="65" border="0"
onclick="setfie lds()"></p>
<input type="text" name="mycity" size="24">
<input type="submit" name="submit">
</form>
<IFRAME name="theiframe "
SRC="http://www.example.com/cityinfo.html" width="95%" height="90%"
scrolling="auto " frameborder="1" >
</IFRAME>

</body>
</html>

this line doesn't seem to kick:

document.theifr ame.document.fo rms[1].city.value='pa ris';

unfortunately, the form on the example.com site does not have a name for
referencing, so I have to reference it as forms[1]... I understand that
this might make the form read only... is there a way to reference it
that's not read only? (or am I off base in my diagnostic?)

the example.com is not a site that I have any control over... gotta work
with what I gots.

thanks much, javascript gurus and galus.
B.


Jul 23 '05 #2
Bob wrote:
I'm a total newbie at Javascript, but a programmer for over 20 years...
so, my plans may be bigger than they are possible.

I'm trying to set with Javascript the value of a form field... easy
enough, right?

e.g. this successfully sets the local form's field:

document.thetes tform.mycity.va lue='paris';


however, I'm not sure how to do the same for a form that's within an
iframe, e.g. (consider that the remote url at example.com has 2 forms in
it; the 2nd frame contains a field called 'city' that I want to set):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1">
<SCRIPT LANGUAGE="JavaS cript" type="text/javascript">
<!--
function setfields()
{
document.theifr ame.document.fo rms[1].city.value='pa ris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#fffff f">
<form action="test.vs p" method="get" name="thetestfo rm"
enctype="applic ation/x-www-form-urlencoded">
<p><img src="clickme.gi f" alt="" width="90" height="65" border="0"
onclick="setfie lds()"></p>
<input type="text" name="mycity" size="24">
<input type="submit" name="submit">
</form>
<IFRAME name="theiframe "
SRC="http://www.example.com/cityinfo.html" width="95%" height="90%"
scrolling="auto " frameborder="1" >
</IFRAME>

</body>
</html>


this line doesn't seem to kick:

document.theifr ame.document.fo rms[1].city.value='pa ris';

unfortunately, the form on the example.com site does not have a name for
referencing, so I have to reference it as forms[1]... I understand that
this might make the form read only... is there a way to reference it
that's not read only? (or am I off base in my diagnostic?)

the example.com is not a site that I have any control over... gotta work
with what I gots.
thanks much, javascript gurus and galus.
B.


The only way this is possible is if your main page, and 'sub page' (be
it a iframe, frame or popup) are hosted from the same domain. This is
not clear from your example code above...

What is the problem?

Its a security issue and if you do manage to resolve it, the results
will be unreliable because many browsers have closed this hole a few
years ago.

If your intentions are for the best, then think... Think of one frame
1pixel wide, 1pixel long hidden in a page somewhere - If you could do
what you want to do, you could read the form input like someone's
username/password meant for another website - perhaps bank details -
whatever - and save them by auto-posting your form...

cheers
randelld

Jul 23 '05 #3
Bob
In article <KAmLd.228440$8 l.128239@pd7tw1 no>,
"Randell D." <re************ *************** ***@fiprojects. moc> wrote:
Bob wrote:
I'm a total newbie at Javascript, but a programmer for over 20 years...
so, my plans may be bigger than they are possible.

I'm trying to set with Javascript the value of a form field... easy
enough, right?

e.g. this successfully sets the local form's field:

document.thetes tform.mycity.va lue='paris';


however, I'm not sure how to do the same for a form that's within an
iframe, e.g. (consider that the remote url at example.com has 2 forms in
it; the 2nd frame contains a field called 'city' that I want to set):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1">
<SCRIPT LANGUAGE="JavaS cript" type="text/javascript">
<!--
function setfields()
{
document.theifr ame.document.fo rms[1].city.value='pa ris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#fffff f">
<form action="test.vs p" method="get" name="thetestfo rm"
enctype="applic ation/x-www-form-urlencoded">
<p><img src="clickme.gi f" alt="" width="90" height="65" border="0"
onclick="setfie lds()"></p>
<input type="text" name="mycity" size="24">
<input type="submit" name="submit">
</form>
<IFRAME name="theiframe "
SRC="http://www.example.com/cityinfo.html" width="95%" height="90%"
scrolling="auto " frameborder="1" >
</IFRAME>

</body>
</html>


this line doesn't seem to kick:

document.theifr ame.document.fo rms[1].city.value='pa ris';

unfortunately, the form on the example.com site does not have a name for
referencing, so I have to reference it as forms[1]... I understand that
this might make the form read only... is there a way to reference it
that's not read only? (or am I off base in my diagnostic?)

the example.com is not a site that I have any control over... gotta work
with what I gots.
thanks much, javascript gurus and galus.
B.


The only way this is possible is if your main page, and 'sub page' (be
it a iframe, frame or popup) are hosted from the same domain. This is
not clear from your example code above...

What is the problem?

Its a security issue and if you do manage to resolve it, the results
will be unreliable because many browsers have closed this hole a few
years ago.

If your intentions are for the best, then think... Think of one frame
1pixel wide, 1pixel long hidden in a page somewhere - If you could do
what you want to do, you could read the form input like someone's
username/password meant for another website - perhaps bank details -
whatever - and save them by auto-posting your form...

cheers
randelld


Like Randell guessed, the inner page is not coming from my domain, it's
an external page.

thanks for the heads up, I'm screwed with this approach.

saved me wasting more time, thanks.
B
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
18351
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically submitted and the target is set to the IFrame. I want to detect when the frame has been loaded with the result of the form submit. Of course I have tried some event handlers like onload, onactivate, onreadystatechange, but they do not work in this example. They only seem to work, when the "SRC"...
7
3614
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
2
2423
by: starman7 | last post by:
i have an app i need to login to that requires several credentials, instead of typing them (or having the browser remember some of them), i call the login page in an iframe, which itself is in the bottom pane of a two frame frameset. fwiw, the login page the iframe calls is on a different server. i would like to click a button (or link) in the top pane and populate fields in the bottom frame --> iframe, e.g. my username password,...
7
4865
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh'; this.iframe.style.display = 'none';
18
18409
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
3
2733
by: Mike | last post by:
Hello: I was not able to find a regular ASP group, so I posted this here instead. I have a web app which is actually just ASP using VBScript as the server-side language, running on IIS6. Users will log into the site and enter in large amounts of data in forms and submit this data to be saved to the database. Problem is, sometimes they submit the data after the session has timed out. This makes them very angry when they have just...
2
2338
by: Jon | last post by:
All, I'm currently working with a PHP-based CMS application, and am begining to put the finishing touches on it via Javascript validation. Currently, I'm using fairly standard methods of validation of each form field, the algorithm is much like: if(document.formName.field.value == ""){ //throw an error and return false }
2
2788
jayfrankland
by: jayfrankland | last post by:
Hello: I have a form called ApplicationFees that contains a field value called Project_Id. Within the page I also have an iframe. I need to get or request the Project_Id value from the ApplicationFees form into a field into my iframe. How would I do that?
2
1453
by: Defacta | last post by:
Hi ! How can I send a form in an iframe ? My code looks like that: <iframe name="Main_IF" id="Main_IF" width="686" height="440" src="iframe_login.php"</iframe> <form name="login" action="Mon Iframe" method=post> <label for="password">Le mot de passe:</label> <input type="password" name="password" id="password"
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.