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.
Greg Griffiths - 31 Jan 2005 01:37 GMT
It could be a security issue, copy all the code and IFRAMES to you local
machine and then retry.
> I'm a total newbie at Javascript, but a programmer for over 20 years...
> so, my plans may be bigger than they are possible.
[quoted text clipped - 54 lines]
> thanks much, javascript gurus and galus.
> B.
Randell D. - 31 Jan 2005 09:08 GMT
> I'm a total newbie at Javascript, but a programmer for over 20 years...
> so, my plans may be bigger than they are possible.
[quoted text clipped - 54 lines]
> 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
Bob - 31 Jan 2005 23:50 GMT
> > I'm a total newbie at Javascript, but a programmer for over 20 years...
> > so, my plans may be bigger than they are possible.
[quoted text clipped - 73 lines]
> 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