472,378 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Run JavaScript before Form Submits

Hi
How can I run a java script function before a form is submited back to the
server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.
Nov 18 '05 #1
14 1716
Instead of using a submit button on your form, use a regular HTML button
that has an onClick event handler on it that calls a function.

In that function, do whatever you like and when you are done invoke
formName.submit()
"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to the server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.

Nov 18 '05 #2
Ok then,
But what Serverside code is required to make sure the submit button was
pressed and not a clear or browser refresh button.

"Scott M." <s-***@badspamsnet.net> wrote in message
news:eN**************@TK2MSFTNGP11.phx.gbl...
Instead of using a submit button on your form, use a regular HTML button
that has an onClick event handler on it that calls a function.

In that function, do whatever you like and when you are done invoke
formName.submit()

Nov 18 '05 #3
call the javascript function and then return true.
the form will be submitted as normal.
eg
myButton.Attributes.add("onclick","doThisFirst();" );

on the page

<script>
function doThisFirst() {
alert('hello');
return true;
}
</script>
"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to the server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.

Nov 18 '05 #4
Yep, this is why I am having such hard time seeing the
benefits of ASP.NET. So far I feel like they turned ASP
development with .NET into a beefed up version of
FrontPage. Where as on the windows side of things I think
it is a huge improvement.
-----Original Message-----
Instead of using a submit button on your form, use a regular HTML buttonthat has an onClick event handler on it that calls a function.
In that function, do whatever you like and when you are done invokeformName.submit()
"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in messagenews:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to
the
server.
What I wish to do is have a upload form that when a

user clicks the submit button a javascript function opens a second window after this the buttons onclick event should be run.

Is any of this possible.

.

Nov 18 '05 #5
Oh, I think you haven't worked with it long then. It is a completely new
paradigm. Much more powerful. Much more scaleable. Not even close to
anything that FP can do.

It just so happens that your question wasn't really a .NET question. It was
a client-side JavaScript question.
"dingo" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
Yep, this is why I am having such hard time seeing the
benefits of ASP.NET. So far I feel like they turned ASP
development with .NET into a beefed up version of
FrontPage. Where as on the windows side of things I think
it is a huge improvement.
-----Original Message-----
Instead of using a submit button on your form, use a

regular HTML button
that has an onClick event handler on it that calls a

function.

In that function, do whatever you like and when you are

done invoke
formName.submit()
"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in

message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to
the
server.
What I wish to do is have a upload form that when a

user clicks the submit button a javascript function opens a second window after this the buttons onclick event should be run.

Is any of this possible.

.

Nov 18 '05 #6
In the page_load event...

If IsPostBack() Then
'Second or subsequent trip to the server

Else
'Fist time data was submitted

End If

"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Ok then,
But what Serverside code is required to make sure the submit button was
pressed and not a clear or browser refresh button.

"Scott M." <s-***@badspamsnet.net> wrote in message
news:eN**************@TK2MSFTNGP11.phx.gbl...
Instead of using a submit button on your form, use a regular HTML button
that has an onClick event handler on it that calls a function.

In that function, do whatever you like and when you are done invoke
formName.submit()


Nov 18 '05 #7
> Instead of using a submit button on your form, use a regular HTML button
that has an onClick event handler on it that calls a function.

At the HTML level form objs have a OnSubmit() and OnReset() events
handlers...

With...

1) In you script tag...
function verifyForm(IncomingForm)
{
if(FORMISVALID)
return true;
else
return false;
}

2) In form tag(1 or more forms supported cause of IncomingForm param above
just send verifyForm(...) this)...
<form ... onSubmit="return verifyForm(this);">...</form>

Now you just need to add you form processing code and your ready to go...
Nov 18 '05 #8
"Scott M." <s-***@badspamsnet.net> wrote in message
news:eD*************@TK2MSFTNGP11.phx.gbl...
In the page_load event...

If IsPostBack() Then
'Second or subsequent trip to the server

Else
'Fist time data was submitted

End If


OK but this doesn't stop the submit code from running if you press a
different button or refresh the page.
Nov 18 '05 #9
SSW
Use Javscript below
<script language="javascript">
function ConfirmOnSummit()
{
if (typeof(Page_ClientValidate) == 'function')
{
if (Page_ClientValidate())
{
if(confirm("What Ever u what to confirm or run a Java Script
code?")==1)
return true;
else
return false;
}
}
}
</script>
Create tage in aspx page.
<span onclick="javascript: return ConfirmOnSummit();"><asp:button
id="btnSubmit" runat="server" CausesValidation="False"
Text="Submit"></asp:button></span>

This Will surely work. It take all the advantage of Asp.Net

Thanks,

sswalia
MCAD, MCAD, OCA

"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to the server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.

Nov 18 '05 #10
SSW
Sorry Please igonre above solution. It's not for you.
"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to the server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.

Nov 18 '05 #11
try
Page.RegisterOnSubmitStatement

"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
Hi
How can I run a java script function before a form is submited back to the server.
What I wish to do is have a upload form that when a user clicks the submit
button a javascript function opens a second window after this the buttons
onclick event should be run.

Is any of this possible.

Nov 18 '05 #12
OK then, but how do I use it, A sample would be nice.

"Joe Gass" <jo*@dontspamme.com> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
try
Page.RegisterOnSubmitStatement

Nov 18 '05 #13

"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uB**************@TK2MSFTNGP10.phx.gbl...
"Scott M." <s-***@badspamsnet.net> wrote in message
news:eD*************@TK2MSFTNGP11.phx.gbl...
In the page_load event...

If IsPostBack() Then
'Second or subsequent trip to the server

Else
'Fist time data was submitted

End If


OK but this doesn't stop the submit code from running if you press a
different button or refresh the page.


If you refresh the page, you are not re-submitting the data, you are
re-requesting the page with whatever data was posted previously.

If you want to prevent ASP.NET server-side code from running you could use
only HTML controls and the client-side JavaScript I described in my earlier
post.
Nov 18 '05 #14
http://msdn.microsoft.com/library/en...ementTopic.asp

"Kenneth Keeley" <ke*******@hotmail.com.nowhere> wrote in message
news:uk*************@TK2MSFTNGP10.phx.gbl...
OK then, but how do I use it, A sample would be nice.

"Joe Gass" <jo*@dontspamme.com> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
try
Page.RegisterOnSubmitStatement


Nov 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
6
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: ...
8
by: ryan | last post by:
that will make sure all fields are entered. make sure age is between 3- 99 and make sure the email is valid I had a decent search on google, nothing really comes up that is complete. I am...
8
by: nektir | last post by:
I have an external js file to validate a form and it works in IE and Opera, but not Mozilla Firefox. In Mozilla Firefox, the javascript console sasys "SearchForm" is not defined in the second...
2
by: mylo1968 | last post by:
Hello Experts, in the following link there is fine tool for javascript client-side form validation, as some of you I guess/hope know: ...
14
Plater
by: Plater | last post by:
I'm going to stab myself in the face. I have a page with a single form. Regular old html. There are a few checkboxes and textboxes and and two submit buttons (I hope that's not the issue...) The...
6
by: 0utlawza | last post by:
Hi Guys It seems i posted this in the incorrect topic, so i am reposting here. Please excuse the Newbie question. I am not really a programmer so excuse me if i dont clarify my point...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.