473,563 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript - ASP

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="testRe sults(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
6 1398
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="testRe sults(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="testRe sults(this.form )" value="Submit" >

now use your function testResults to submit the form.
something like:
document.forms["formnamehe re"].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
Thanks a lot mate ! You couldn't be more helpful.

Jul 23 '05 #3
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="testRe sults(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="testRe sults(this.form )" value="Submit"
now use your function testResults to submit the form.
something like:
document.forms["formnamehe re"].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
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="testRe sults(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="testRe sults(this.form )" value="Submit"
now use your function testResults to submit the form.
something like:
document.forms["formnamehe re"].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
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="testRe sults(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="testRe sults(this.form )" value="Submit"

now use your function testResults to submit the form.
something like:
document.forms["formnamehe re"].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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.