Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Run JavaScript before Form Submits

Reply
Thread Tools

Run JavaScript before Form Submits

 
 
Scott M.
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in message
news:uI9La$...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Kenneth Keeley
Guest
Posts: n/a
 
      11-17-2003
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.


 
Reply With Quote
 
 
 
 
Andrew de la Harpe
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in message
news:uI9La$...
> 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.
>
>



 
Reply With Quote
 
dingo
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in

message
>news:uI9La$...
>> 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.
>>
>>

>
>
>.
>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in message
news:039901c3acbb$ecd72390$...
> 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" <> wrote in

> message
> >news:uI9La$...
> >> 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.
> >>
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in message
news:...
> 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-> wrote in message
> news:...
> > 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()
> >
> >

>
>



 
Reply With Quote
 
lewi
Guest
Posts: n/a
 
      11-17-2003
> 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...


 
Reply With Quote
 
Kenneth Keeley
Guest
Posts: n/a
 
      11-17-2003
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-> wrote in message
news:...
> 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()
>
>



 
Reply With Quote
 
Kenneth Keeley
Guest
Posts: n/a
 
      11-17-2003
"Scott M." <s-> wrote in message
news:...
> 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.


 
Reply With Quote
 
SSW
Guest
Posts: n/a
 
      11-17-2003
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" <> wrote in message
news:uI9La$...
> 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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation controls validate before form submits TS ASP .Net Web Controls 5 06-28-2005 02:23 PM
Form no longer submits - client validator problem? Wysiwyg ASP .Net 2 04-25-2005 11:18 PM
autoselect all items in <SELECT> control is undone when form submits Mad Scientist Jr ASP .Net 1 03-05-2004 08:56 PM
Linkbutton submits the form but OnClick event does not get fired Stan ASP .Net 1 12-03-2003 03:11 AM
Help needed with form submits and Perl handling Robert V Perl 1 07-21-2003 05:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57