Javascript - ASP

  • Thread starter Marios Koumides
  • Start date
M

Marios Koumides

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
 
E

Erwin Moller

Marios said:
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
 
R

RobB

Erwin said:
Marios said:
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?
 
E

Erwin Moller

RobB said:
Erwin said:
Marios said:
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.

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.
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
 
R

RobB

Erwin said:
RobB said:
Erwin said:
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.

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.


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:

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

Erwin Moller

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:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top