473,378 Members | 1,209 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,378 software developers and data experts.

Submit() in javascript

NawazAhmed
Hi,
Is it possible to get the page1's form values to page2. I know about submit button and submit function but when I am trying to get the values in page 2 with the help of Request.form("FieldName") it gives me error: Request is undefined.
Can anyone help me with this.
My code is something like this:
Page1:
in html:
[HTML]<INPUT id="FieldName" maxLength="35" name="FieldName">
<input id="Button1" onclick="javascript:Submit()" type="button" value="Continue" name="Button1">
[/HTML]
the javascript function is:
Expand|Select|Wrap|Line Numbers
  1. function Submit() {
  2.    document.forms[0].submit();
  3.    window.location.href = "page2.aspx"    
  4.    }
  5.  
Page2:
vbscript:
x = Request.Form("FieldName")

Thanks.
Feb 27 '08 #1
18 2905
acoder
16,027 Expert Mod 8TB
Don't set the location.href if you're submitting. Set the action property of the form instead to this location.
Feb 28 '08 #2
Thanks for the Reply,
As you set I tried that also. If my form is
<form id="frm1" name="frm1" action="page2.aspx" method="post" runat="server">

and the button is

<input id="Button1" onclick="javascript:Submit()" type="button" value="Continue" name="Button1">

and javascript is
document.forms[0].submit();

It submits the form but wont forward to the next page.

Waiting for your reply,
Thanks.

Don't set the location.href if you're submitting. Set the action property of the form instead to this location.
Feb 28 '08 #3
hsriat
1,654 Expert 1GB
In your code, you are submitting the form to page2.aspx and then redirecting it to the same page, ie. page2.aspx. If that is the case, then you don't need to redirect it.

But if you need to redirect it to some other page, then after processing the form data in page2.aspx, add this to the end of your ASP code...
Expand|Select|Wrap|Line Numbers
  1. Response.AddHeader("Location","page3.aspx");
Feb 28 '08 #4
I am sorry if I am not clear, Iam new to XML.
So from your message what I understand is if you mention the action in form tab then it directs you to the mentioned page(in action). But its not doing that.
Its submitting the text but not forwarding to the next page and if I am transfering it to next page(with the statement window.location.href = "page2.aspx"). there I cannot able to get the submitted value from the previous page as I said in the 1'st post.

Any suggestions.........


In your code, you are submitting the form to page2.aspx and then redirecting it to the same page, ie. page2.aspx. If that is the case, then you don't need to redirect it.

But if you need to redirect it to some other page, then after processing the form data in page2.aspx, add this to the end of your ASP code...
Expand|Select|Wrap|Line Numbers
  1. Response.AddHeader("Location","page3.aspx");
Feb 28 '08 #5
acoder
16,027 Expert Mod 8TB
Its submitting the text but not forwarding to the next page
If it submits the text, it should submit to the action page. Which pagedo you want to forward to?
Feb 29 '08 #6
I want to direct it to page 2 and its not directing automatically so I am using
window.location.href = "page2.aspx" in the javascript of page1.aspx
But the problem is when I am tring to retrieve page1 form's data by using the statement Request.Form("FieldNameofPage1'sControl") its gives me error:
Request is undefined.

If it submits the text, it should submit to the action page. Which pagedo you want to forward to?
Feb 29 '08 #7
acoder
16,027 Expert Mod 8TB
So that means the form doesn't submit.

Post the client-side code (load the page and view source in the browser).
Feb 29 '08 #8
hsriat
1,654 Expert 1GB
Instead of [html]<input id="Button1" onclick="javascript:Submit()" type="button" value="Continue" name="Button1">[/html]try this....[html]<input id="Button1" type="submit" value="Continue" name="Button1"></input>[/html]

PS: Is there any special reason to use onclick="javascript:Submit()"?
Feb 29 '08 #9
Page1:
source:
[HTML]<HTML>
<Head>
<script Language=javascript src="Page1.js"></script>
</Head>
<body>
<form id="Form1" method="post" action="Page2.aspx">
<DIV style="DISPLAY: inline; Z-INDEX: 101; LEFT: 56px; WIDTH: 112px; POSITION: absolute; TOP: 120px; HEIGHT: 24px">License Number</DIV>
<INPUT style="Z-INDEX: 103; LEFT: 192px; POSITION: absolute; TOP: 120px" type="text" name="txtName">
<INPUT style="Z-INDEX: 102; LEFT: 152px; POSITION: absolute; TOP: 168px" type="button" value="Button" onclick="javascript submit();">
</form>
</body>
</HTML>
[/HTML]
Page1.js:
Expand|Select|Wrap|Line Numbers
  1. Function submit(){
  2. document.form.submit();
  3. window.location.href = "Page2.aspx" // If I remove this line page1 is not
  4. // forwarding to Page2
  5. }
  6.  
Page2.aspx
[HTML]<HTML>
<Head>
<script Language=javascript >
var x = Request.Form("txtName");
alert(x.value);
</script>
</Head>
<body>
</body>
</HTML>
[/HTML]
According to the above code the answer should be name entered by the user on the first page

If I use the button type=submit and in form tab action="page2.aspx" method = "post", its not going to the next page, even if it goes to the next page getting the error Request is undefined.

Thanks.
So that means the form doesn't submit.

Post the client-side code (load the page and view source in the browser).
Mar 3 '08 #10
Hi hsriat,
I tried type=submit, problem with this is it won't forward to the next page when u specify action="page2.aspx",
and why I am using onclick="javascript:Submit()" is bcz I have to validate the fields on the form and then submit and move to the next page.
I already posted the code, why don't u try once
If you find something please lemme know.

Thanks

Instead of [html]<input id="Button1" onclick="javascript:Submit()" type="button" value="Continue" name="Button1">[/html]try this....[html]<input id="Button1" type="submit" value="Continue" name="Button1"></input>[/html]

PS: Is there any special reason to use onclick="javascript:Submit()"?
Mar 3 '08 #11
hsriat
1,654 Expert 1GB
Didn't you try the common way of validation?
ie.[html]<form action="action.php" method="get | post" onsubmit="return validate()">
<!--
form inputs
-->
<input type="submit" name="submit" value="Continue"></input>
</form>[/html]See if this helps you.
Mar 3 '08 #12
I tried my problem is not with submission, my major problem is Request.Form
This statement is the main cause of error.
Accordingly this staement should return the fields value whatever we are calling but it won't recognize Request. The error is Request is undefined.
Do I have to include any system files or inhert something?????

Thanks.
Didn't you try the common way of validation?
ie.[html]<form action="action.php" method="get | post" onsubmit="return validate()">
<!--
form inputs
-->
<input type="submit" name="submit" value="Continue"></input>
</form>[/html]See if this helps you.
Mar 3 '08 #13
acoder
16,027 Expert Mod 8TB
NawazAhmed, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks!

Moderator.
Mar 4 '08 #14
acoder
16,027 Expert Mod 8TB
Page2.aspx
[HTML]<HTML>
<Head>
<script Language=javascript >
var x = Request.Form("txtName");
alert(x.value);
</script>
</Head>
<body>
</body>
</HTML>
[/HTML]
Request.Form should be within server-side tags. JavaScript will not recognise it.
Mar 4 '08 #15
What do you mean by that? Could you please explain me clearly.
It would be better if you can give me an example.
Thanks.

Request.Form should be within server-side tags. JavaScript will not recognise it.
Mar 4 '08 #16
hsriat
1,654 Expert 1GB
What do you mean by that? Could you please explain me clearly.
It would be better if you can give me an example.
Thanks.
I guess...
Expand|Select|Wrap|Line Numbers
  1. var x = <%Request.Form("txtName")%>;
Mar 4 '08 #17
Thanks. Now I understand that the submitted data can be requested from the server side only.

Thanks alot.
I guess...
Expand|Select|Wrap|Line Numbers
  1. var x = <%Request.Form("txtName")%>;
Mar 4 '08 #18
acoder
16,027 Expert Mod 8TB
Glad to hear that you got it working. Post again if you have any more questions.
Mar 5 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jimbo | last post by:
I am trying to right a script so that the "submit button" only appears when certain criteria has been met. I have tried putting it in an IF statement, without any luck. Maybe a function would allow...
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
2
by: DB | last post by:
Hi All Having stared at this all morning and altered various things with no effect other then to exasperate the problem i'm wondering if anyone could take a look at the code below and see why on...
2
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I...
1
by: jrefactors | last post by:
When the user type something in text box, and press enter, it will submit the form data to test2.jsp, even without pressing submit form button. This is not what I want, I want to submit the form...
8
by: horos | last post by:
hey all, Ok, a related question to my previous one on data dumpers for postscript. In the process of putting a form together, I'm using a lot of placeholder variables that I really don't care...
5
by: terence.parker | last post by:
I have a PHP application which I wrote last year - and the JavaScript worked fine then. For some reason, now it doesn't - neither on IE nor Firefox. Has something changed? When I click on my...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
11
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.