Bug in JavaScript Form Submitting

I have written an ASP script which generates a number of FORMS, each with a different ID and each with an <A HREF="javascript:<formid>.submit();"> link. This scenario works correctly.

Unfortunatly this page is in a frame and the resulting page should fill the whole browser window.

As soon as I add a TARGET="_top" to the HREF tag, or a <BASE TARGET="_top"> to the page, then the submits fail to work, reporting that the ID is Invalid.

The problem occurs in both IE and NS.

Does anyone know a way around this?
LVL 1
rpmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HooliganCommented:
could you  post your actual code?
0
rpmAuthor Commented:
Ok, here it is. I hope that it makes sense!

<BODY BGCOLOR="WHITE">

<BASE TARGET="_top">

<% PI = Request.QueryString("pi")
   SC = Request.QueryString("sc") %>

<%
   Set DBCon = Server.CreateObject("ADODB.Connection")
   DBCon.Open "FBz"
   SQLQuery = "SELECT S_ID, S_Name, S_Desc FROM Starters WHERE S_Cat=" & SC
   Set Results = DBCon.Execute(SQLQuery)
%>

<% if SC = 0 then %>

<P>Please select a category of starter from the list above...</P>

<% else %>

<P>Please choose a starter from the list below, or choose another category from the list above.</P>

<% Do While Not Results.EOF %>

<FORM ID="f<%= Results("S_ID") %>" METHOD="POST" ACTION="party03.asp">
<INPUT TYPE="HIDDEN" NAME="PI" VALUE="<%= PI %>">
<INPUT TYPE="HIDDEN" NAME="CS" VALUE="<%= Results("S_ID") %>">
<P ALIGN="CENTER"><FONT FACE="BLACKADDER ITC, ARIAL" SIZE="6"><B><A HREF="javascript:f<%= Results("S_ID") %>.submit();"><%= Results("S_Name") %></A></B></FONT><BR>
<FONT FACE="VERDANA, ARIAL" SIZE="3"><%= Results("S_Desc") %></FONT></P>
</FORM>

<% Results.MoveNext
   Loop %>

<% end if %>

</BODY>
0
aarieCommented:
Can you post the resulting html code? Without the asp tags in it.

Arjan.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

rpmAuthor Commented:
Ok, I have just copied one of the Forms that were created, the rest just take similar form.

<FORM ID="f21" METHOD="POST" ACTION="party03.asp">
<INPUT TYPE="HIDDEN" NAME="PI" VALUE="15">
<INPUT TYPE="HIDDEN" NAME="CS" VALUE="21">
<P ALIGN="CENTER"><FONT FACE="BLACKADDER ITC, ARIAL" SIZE="6"><B><A HREF="javascript:f21.submit();">Carrot Consommé</A></B></FONT><BR>
<FONT FACE="VERDANA, ARIAL" SIZE="3">With Ravioli Scented With Coriander</FONT></P>
</FORM>
0
DreamMasterCommented:
why don't You try writing a javascript function that will escape Your frameset when You submit the form using onSubmit?
0
rpmAuthor Commented:
Sounds promising, but I don't have a clue how to do that!
0
DreamMasterCommented:
<script language="javascript">
<!--
function jumptotop()
{
  parent.location = location.href;
}
//-->

<form onsubmit="javascript:jumptotop()">

i have to admit i didn't test this yet..as i'm pretty busy right now...but something along these lines should do it....
0
rpmAuthor Commented:
Sorry! I tried removing the TARGET and inserting your code, but the page still opened in the frame.
0
DreamMasterCommented:
can't stand it when i make errors...tried it myself and found out this DOES work!!!

<html>
<head>
<script language="javascript">
<!--
function jumptotop()
{
  alert(self.location);
  parent.location.replace(self.location);

}
//-->
</script>
</head>
<body>

<form action="" method="post">
<input type="submit" value="submit" onmousedown="jumptotop()">
</form>
</body>
</html>

good luck...need any more help let me know...

Max Davidse
http://www.thekitchen.nl
max@thekitchen.nl
0
DreamMasterCommented:
it's very important to use onmousedown, because as soon as You submit, scripts are ignored...
0
rpmAuthor Commented:
Sorry! I tried removing the TARGET and inserting your code, but the page still opened in the frame.
0
DreamMasterCommented:
did You try the new code? or did You just reload the page and therefor resubmit Your last comment?

i have tested this and it works like a charm...

0
rpmAuthor Commented:
Yes, I did do a refresh.

Unfortunatly the code still does not work correctly.

You may notice in the original code that I am using an <A HREF= ... tag to submit the form and not an <INPUT TYPE=SUBMIT. I do need to do it this way, as I want to submit the form using a text link.

I have tried using <A onmousedown="jumptotop()" HREF="javascript:f<%= Results("S_ID") %>.submit();"> this makes the frame up to a full page but does not submit the form.
0
DreamMasterCommented:
hmm..

strange..

i tried using the text link and altered the code and that does work..

use a function like i did and call that with the <a href>

so

do this...

<html>
<head>
<script language="javascript">
<!--
function jumptotop()
{
  test.submit();
  parent.location.replace(self.location);

}
//-->
</script>
</head>
<body>

<form action="party03.asp" method="post" name="test" enctype="multipart/form-data">
<a href="javascript:jumptotop()">Put on top</a>
</form>
</body>
</html>

that worked for me...

both the form was submitted and the frame was jumped out (bad english i know but hey shout me...i'm dutch ;-)
0
DreamMasterCommented:
did You check that out? and did it work?
0
rpmAuthor Commented:
Sorry once again!

I have tried to use your code in my scripts and it did not work. Then I copied the entire script from your previous comment into a separate file, and this on its own still would not work.

The frame is selected correctly but the form is not submitted.

I have tried it using IE5 which simply did not submit the form and NS4.05 which gave an error (test is not defined)
0
DreamMasterCommented:
the form is not submitted?

i on purpose used party3.asp so i would see if Your form is submitted and both in IE5, and IE4 it works. I get a page does not exist (party3.asp)

but i think You want to load partyo3.asp in the top layer...if so

all You need to do is, in that page use the lines
<html>
<head>
<script language="javascript">
<!--
function loadpageontop()
{
  if (parent.location != self.location)
   {parent.location.replace(self.location);
    alert(parent.location);
   }
}
//-->
</script>

</head>
<body onload="javascript:loadpageontop()">

</body>
</html>


if that doesn't work somebody please kill me!!
0
rpmAuthor Commented:
The good news is that this works!

The bad news is that the form data is lost, so I cannot process the results of the form.
0
DreamMasterCommented:
what exactly do You mean?

You can use ASP right, then You could put the values in session variables which You can then recall later...
0
rpmAuthor Commented:
I suspect that this is the solution that I will have to use. In which case I will not need to post a form at all!

It still seems odd to me that there is aparently not a way of doing what seemed to be such a simple thing!
0
DreamMasterCommented:
i'm sorry to say that it seems to me that there isn't!

Actually when i first looked at Your question, it was hard for me to even understand what it was that You meant to do, well at least we got around to solving Your question right?

I hope my answers to You have been helpfull contact me whenever You wish if You have any other questions.

Max Davidse
http://www.thekitchen.nl
max@thekitchen.nl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rpmAuthor Commented:
Ok, I'll accept this conclusion as an answer, it is hardly your fault that I wanted the impossible!

Thank you for all of your help, I have learnt quite a bit from your code examples.
0
DreamMasterCommented:
Hey You're welcome....anytime...as i said, feel free to contact me whenever You have a problem to fix...

Max Davidse...out
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.