I am trying to submit a form with .submit(), but I am having issues passing the values from my form...

Here is what I have so far:

<TITLE>ASPXTOASP.aspx</TITLE>
<script language="C#" runat="server">
 
private void Page_Load(object sender, EventArgs e){
//We grab all the session variable names/values and stick them in a form
// and then we submit the form to our receiving ASP page (ASPTOASPX.asp)...
 
    Response.Write("<form name=t id=t action=ASPXTOASP.asp method=post>");
 
 foreach(object it in Session.Contents)
    {
        Response.Write("<input type=hidden name=" + it.ToString());
        Response.Write(" id=" + it.ToString());
        Response.Write( " value=" + Session[it.ToString()].ToString() + " >");
    }
 
if (Request.QueryString["destpage"] !=null)
Response.Write("<input type=hidden name=destpage value=" +Request.QueryString["destpage"].ToString() +">");
Response.Write("</FORM>");
Response.Write("<scr" + "ipt>t.submit();</scr" + "ipt>");
}
 
</script>

As luck would have it, I have no problems with this in IE. I have tried everything that I can think of to get it to work in Firefox... document.forms(0).submit(), document.getElementById("t").value.submit, etc, and nothing is working.

Thanks!

Anyone have any ideas?

If anyone has another other ideas I am definitely open... I am trying to pass session variables from an ASPX page to an ASP page. Like I mentioned before it works fine in IE, but not in Firefox. If it could be rewritten in javascript or something else please let me know. The major issue that I am having is getting the form values t not to cause a "has no properties error".

document.getElementById("t").submit( ), or document.forms["t"].submit(); should work.. It may be the case that the inline script isn't running at the right time, or that the form cant be auto-submitted from inline script... if that was the case you'd need a body 'onload' handler in javascript to invoke the submission of the form.. but, I can't see a good reason why inline submit should be problem.

If it still doesn't work with either those changes, please post the HTML output ( via View Source ) when that page is accessed in the browser.

That's a really messy way to pass values between two scripts sitting on the same server.. Don't you think it's a good idea to include a <html>, <head>, <body> element, and to quote the attributes of elements? Dunno if ASP decides to add/fix those things for you on output.. so ignore that comment if that's the case.

Here is the HTML that view source gives me. It is passing everything I need to the browser...

<form name=t id=t action=ASPXTOASP.asp method=post><input type=hidden name=username id=username value=cpio@email.com ><input type=hidden name=password id=password value=mypw ><input type=hidden name=destpage id=destpage value=login.asp></FORM><TITLE>ASPXTOASP.aspx</TITLE>

I changed the code a little, but it did not make a difference...

<script language="C#" runat="server">

private void Page_Load(object sender, EventArgs e){

    Response.Write("<form name=t id=t action=ASPXTOASP.asp method=post>");
    foreach(object it in Session.Contents)
	{
		Response.Write("<input type=hidden name=" + it.ToString());
        Response.Write(" id=" + it.ToString());
        Response.Write(" value=" + Session[it.ToString()].ToString() + " >");
        
    }
   
if (Request.QueryString["destpage"] !=null)
Response.Write("<input type=hidden name=destpage id=destpage value=" +Request.QueryString["destpage"].ToString() +">");

    Response.Write("</FORM>");
        
}

</script>

<script language="javascript">
//alert(document.forms["t"].submit());
document.forms["t"].submit();
</script>

Well.. I notice your javascript has disapeared from the output.. Why did you change the way you were outputing it? When I said, don't put the Javascript inline... that isn't exactly what I meant.

Certainly output a valid HTML document. Firefox is a bit nitpicky about standards.. What is printed is interpretted as a document, and whilst you can get quite... badly formed documents that still 'work', I'd advise that everytime you output anything to the browser; even something as short and invisible as this; that you make sure the document it is encapsulated in is a halfway valid document..

So.. I'm gonna tell you what you should try and get your script to output.. I'm not gonna rewrite your server script.. I'll leave that to you.. I've quoted attributes, which might seem a problem since you're allready quoting strings.. I've tried as hard as possible to only use single quotes; but there are a few places where I had to use double quotes... You'll have to escape those double quotes. If you don't know how.. read bottom few lines of this post.

Ok. You want your server script to output this exact HTML. It works, in Firefox, and Opera.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<TITLE>ASPXTOASP.aspx</TITLE>
</HEAD>
<BODY onload='document.forms["t"].submit( );'>

<FORM name='t' id='t' action='ASPXTOASP.asp' method='post'>
	<INPUT type='hidden' name='username' id='username' value='cpio@email.com' >
	<INPUT type='hidden' name='password' id='password' value='mypw' >
	<INPUT type='hidden' name='destpage' id='destpage' value='login.asp' >
</FORM>

</BODY>
</HTML>

To escape the double quotes; like in the first 'DOCTYPE' part, use a backslash directly before any " that's within " quotes. Otherwise, the string ends abrubtly.

Response.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");

The only other place where double quotes appear in that HTML are around the 't' here: <BODY onload='document.forms["t"].submit( );'>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.