473,387 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.thetestform.mycity.value='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=ISO-8859-1">
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function setfields()
{
document.theiframe.document.forms[1].city.value='paris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#ffffff">
<form action="test.vsp" method="get" name="thetestform"
enctype="application/x-www-form-urlencoded">
<p><img src="clickme.gif" alt="" width="90" height="65" border="0"
onclick="setfields()"></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.theiframe.document.forms[1].city.value='paris';

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 2565
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.thetestform.mycity.value='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=ISO-8859-1">
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function setfields()
{
document.theiframe.document.forms[1].city.value='paris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#ffffff">
<form action="test.vsp" method="get" name="thetestform"
enctype="application/x-www-form-urlencoded">
<p><img src="clickme.gif" alt="" width="90" height="65" border="0"
onclick="setfields()"></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.theiframe.document.forms[1].city.value='paris';

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.thetestform.mycity.value='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=ISO-8859-1">
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function setfields()
{
document.theiframe.document.forms[1].city.value='paris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#ffffff">
<form action="test.vsp" method="get" name="thetestform"
enctype="application/x-www-form-urlencoded">
<p><img src="clickme.gif" alt="" width="90" height="65" border="0"
onclick="setfields()"></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.theiframe.document.forms[1].city.value='paris';

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$8l.128239@pd7tw1no>,
"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.thetestform.mycity.value='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=ISO-8859-1">
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function setfields()
{
document.theiframe.document.forms[1].city.value='paris';
}
//-->
</SCRIPT>
</head>
<body bgcolor="#ffffff">
<form action="test.vsp" method="get" name="thetestform"
enctype="application/x-www-form-urlencoded">
<p><img src="clickme.gif" alt="" width="90" height="65" border="0"
onclick="setfields()"></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.theiframe.document.forms[1].city.value='paris';

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
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...
7
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>...
2
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...
7
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+...
18
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...
3
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. ...
2
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...
2
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.