By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

Javascript - ASP

P: n/a
I have a page written in ASP and I added some Javascript code to
ensure the input boxes are filled with correct data. That check is
performed every time the user moves out from a textbox. Now right
before I submit the form to the server for processing, I want to make
a final test on the values.

<input type="submit" onClick="testResults(this.form)" value="Submit" >

The problem here is that I make the check in the testResults function
and popup an alert, but still the page goes in the server for
processing. How to make it like when there is problem after click
submit to popup an alert and not send the page for processing.

Thanks
Marios Koumides
Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Marios Koumides wrote:
I have a page written in ASP and I added some Javascript code to
ensure the input boxes are filled with correct data. That check is
performed every time the user moves out from a textbox. Now right
before I submit the form to the server for processing, I want to make
a final test on the values.

<input type="submit" onClick="testResults(this.form)" value="Submit" >

The problem here is that I make the check in the testResults function
and popup an alert, but still the page goes in the server for
processing. How to make it like when there is problem after click
submit to popup an alert and not send the page for processing.

Thanks
Marios Koumides


Hi,

2 solutions.

first: Make it a button.
<input type="button" onClick="testResults(this.form)" value="Submit" >

now use your function testResults to submit the form.
something like:
document.forms["formnamehere"].submit();

Second:
use onSubmit instead for onClick.
return false to prevent submitting.

I prefer the first, but that is a matter of taste.
The second approach has the advantage to work if client doesn't have JS
enabled.
But that is also the disadvantage: no checking...
That is why I prefer the first.
(Who doesn't have JS anyway except some companies with bad admins who forbid
anything they don't understand.)

Hope that helps.

Regards,
Erwin Moller
Jul 23 '05 #2

P: n/a
Thanks a lot mate ! You couldn't be more helpful.

Jul 23 '05 #3

P: n/a
Erwin Moller wrote:
Marios Koumides wrote:
I have a page written in ASP and I added some Javascript code to
ensure the input boxes are filled with correct data. That check is
performed every time the user moves out from a textbox. Now right
before I submit the form to the server for processing, I want to make a final test on the values.

<input type="submit" onClick="testResults(this.form)" value="Submit" >
The problem here is that I make the check in the testResults function and popup an alert, but still the page goes in the server for
processing. How to make it like when there is problem after click
submit to popup an alert and not send the page for processing.

Thanks
Marios Koumides
Hi,

2 solutions.

first: Make it a button.
<input type="button" onClick="testResults(this.form)" value="Submit"
now use your function testResults to submit the form.
something like:
document.forms["formnamehere"].submit();

Second:
use onSubmit instead for onClick.
return false to prevent submitting.

I prefer the first, but that is a matter of taste.
The second approach has the advantage to work if client doesn't have

JS enabled.
But that is also the disadvantage: no checking...
No checking...of what?
That is why I prefer the first.
The proper way to validate is via the form's onsubmit handler. The only
reason to call Form.submit() explicitly is because of special form
handling that can't be done any other way.
(Who doesn't have JS anyway except some companies with bad admins who forbid anything they don't understand.)


Plenty of people, sorry. Why lose them unnecessarily?

Jul 23 '05 #4

P: n/a
RobB wrote:
Erwin Moller wrote:
Marios Koumides wrote:
> I have a page written in ASP and I added some Javascript code to
> ensure the input boxes are filled with correct data. That check is
> performed every time the user moves out from a textbox. Now right
> before I submit the form to the server for processing, I want to make > a final test on the values.
>
> <input type="submit" onClick="testResults(this.form)" value="Submit" > >
> The problem here is that I make the check in the testResults function > and popup an alert, but still the page goes in the server for
> processing. How to make it like when there is problem after click
> submit to popup an alert and not send the page for processing.
>
> Thanks
> Marios Koumides
Hi,

2 solutions.

first: Make it a button.
<input type="button" onClick="testResults(this.form)" value="Submit"
now use your function testResults to submit the form.
something like:
document.forms["formnamehere"].submit();

Second:
use onSubmit instead for onClick.
return false to prevent submitting.

I prefer the first, but that is a matter of taste.
The second approach has the advantage to work if client doesn't have

JS
enabled.
But that is also the disadvantage: no checking...


No checking...of what?


Checking of what?
Of the inputfields of course, clientside, before submitting.
What else?
This is what we are talking about.

That is why I prefer the first.
The proper way to validate is via the form's onsubmit handler. The only
reason to call Form.submit() explicitly is because of special form
handling that can't be done any other way.


That is one opinion.

I have another.

I use a lot JS, also for required functionality. (So the site doesn't work
without it.)
For me it is like saying: "You need Flash to see this Flash-movie."

If people don't want JS enabled, so be it.
I don't mind loosing them.

I never had a customer demanding that I made an application that runs
without JS.
I TRY to avoid it, but if I need JS, I just use it.
(Who doesn't have JS anyway except some companies with bad admins who

forbid
anything they don't understand.)


Plenty of people, sorry. Why lose them unnecessarily?


All browsers I have seen the last few years (in a lot of places) had JS
enabled.
I know there are people that don't have it enabled or cannot enable it, but
only of hearsay. :-)

Regards,
Erwin Moller
Jul 23 '05 #5

P: n/a
Erwin Moller wrote:
RobB wrote:
Erwin Moller wrote:
Marios Koumides wrote:

> I have a page written in ASP and I added some Javascript code to
> ensure the input boxes are filled with correct data. That check is > performed every time the user moves out from a textbox. Now right > before I submit the form to the server for processing, I want to make
> a final test on the values.
>
> <input type="submit" onClick="testResults(this.form)"

value="Submit" >
>
> The problem here is that I make the check in the testResults

function
> and popup an alert, but still the page goes in the server for
> processing. How to make it like when there is problem after click > submit to popup an alert and not send the page for processing.
>
> Thanks
> Marios Koumides

Hi,

2 solutions.

first: Make it a button.
<input type="button" onClick="testResults(this.form)" value="Submit"

now use your function testResults to submit the form.
something like:
document.forms["formnamehere"].submit();

Second:
use onSubmit instead for onClick.
return false to prevent submitting.

I prefer the first, but that is a matter of taste.
The second approach has the advantage to work if client doesn't have
JS
enabled.
But that is also the disadvantage: no checking...


No checking...of what?


Checking of what?
Of the inputfields of course, clientside, before submitting.
What else?
This is what we are talking about.

That is why I prefer the first.


The proper way to validate is via the form's onsubmit handler. The only reason to call Form.submit() explicitly is because of special form
handling that can't be done any other way.


That is one opinion.

I have another.

I use a lot JS, also for required functionality. (So the site doesn't

work without it.)
For me it is like saying: "You need Flash to see this Flash-movie."

If people don't want JS enabled, so be it.
I don't mind loosing them.

I never had a customer demanding that I made an application that runs without JS.
I TRY to avoid it, but if I need JS, I just use it.
(Who doesn't have JS anyway except some companies with bad admins
who forbid
anything they don't understand.)

Plenty of people, sorry. Why lose them unnecessarily?


All browsers I have seen the last few years (in a lot of places) had

JS enabled.
I know there are people that don't have it enabled or cannot enable it, but only of hearsay. :-)

Regards,
Erwin Moller


Hi Erwin.

Respectfully - I understand your situation, but this is usenet, and
posters (including the OP) may have different requirements. If you only
used Internet Explorer in your work environment, would it be therefore
unnecessary to bother making your posts here functional cross-browser?
These aren't customers (more's the pity !) and they may be less
sanguine about losing users unnecessarily. And 'unnecessarily' is the
key word here, as you still haven't explained the comment that caught
my attention:
The second approach has the advantage to work if client doesn't
have JS
enabled.
But that is also the disadvantage: no checking...


Then you check at the server, which you should be doing anyway. How is
losing the user/customer entirely preferable?

Jul 23 '05 #6

P: n/a
RobB wrote:

<snip>

Hi Rob,

Hi Erwin.

Respectfully - I understand your situation, but this is usenet, and
posters (including the OP) may have different requirements. If you only
used Internet Explorer in your work environment, would it be therefore
unnecessary to bother making your posts here functional cross-browser?
Well of course not.
I always work crossbrowser.
And I always try to avoid JS for real functionality, but it just isn't
possible in all situations.

These aren't customers (more's the pity !) and they may be less
sanguine about losing users unnecessarily.
I agree with you Rob.
Read on:

And 'unnecessarily' is the key word here, as you still haven't explained the comment that caught
my attention:
>> The second approach has the advantage to work if client doesn't have > JS
>> enabled.
>> But that is also the disadvantage: no checking...

I was saying here that the onSubmit()-approach will have the advantage that
the form will submit regardless of the fact if JS is working.
That is the advantage.
The disadvantage: No checking is done clientside.

So if you really want to do some checks: demand JS.

That is all I wanted to say.

Maybe I said it a little rude and unclear. Sorry for that.


Then you check at the server, which you should be doing anyway. How is
losing the user/customer entirely preferable?


Is that preferable?
Nope.
As I wrote in my original piece: If you can avoid demanding JS, do so.

I was merely making a case for the fact that certain requirements can lead
to demands on the client. Like Flashmovies demand Flash installed.
If you want to do clientside checking: demand JS.

In that context (demanding JS) I don't see much difference between
from.submit() and the onSubmit approach.

I don't think we disagree that much. :-)

Regards,
Erwin Moller
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.