•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,500 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5371 | Replies: 5
![]() |
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:
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!
Here is what I have so far:
c# Syntax (Toggle Plain Text)
<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!
Last edited by rrocket : Nov 6th, 2007 at 2:46 pm.
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".
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation:
Rep Power: 5
Solved Threads: 48
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.
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.
Plato forgot the nullahedron..
Here is the HTML that view source gives me. It is passing everything I need to the browser...
I changed the code a little, but it did not make a difference...
html Syntax (Toggle Plain Text)
<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>•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation:
Rep Power: 5
Solved Threads: 48
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.
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.
The only other place where double quotes appear in that HTML are around the 't' here: <BODY onload='document.forms["t"].submit( );'>
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.
HTML Syntax (Toggle Plain Text)
<!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.
C# Syntax (Toggle Plain Text)
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( );'>
Last edited by MattEvans : Nov 7th, 2007 at 12:14 pm.
Plato forgot the nullahedron..
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp beta bon browser browsers browsing developer development echo email encryption europe firefox gecko home html internet internet explorer internet explorer 7 javascript leak linux memory microsoft mozilla msdn networking news office open source open-source patch phishing scams security site social software sql super testing users vista web webmail
- Javascript fails in Firefox (JavaScript / DHTML / AJAX)
- Checkbox has no properties in FireFox. Works fine in IE (JavaScript / DHTML / AJAX)
- Internet Explorer is not working - Firefox is (Viruses, Spyware and other Nasties)
- Why the following does not work in Firefox (JavaScript / DHTML / AJAX)
- Firefox works but IE6 does not (Web Browsers)
- Style properties are ignored by Mozilla browser... (ASP.NET)
- Downloading with Firefox, or not (Web Browsers)
- after firefox update ie shows no pages but firefox works?? (Web Browsers)
- Dialog Box alongwith Form (Visual Basic 4 / 5 / 6)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript function to switch Classes???
- Next Thread: Enter key does not work in window.showModalDialog


Linear Mode