avascript w/Perl question - Simple for most......

A

amerar

Hi All,

I have a form that uses Javascript to validate some fields. Whe the
user selects to submit the form with certain values selected, I want to
be able to execute a Perl script, query the MySQL database to get my
resuts and return an ALERT box to the user if his form input was
invalid.

Problem is, I do not want to change the screen. I just want the dialog
to pop up. I am very good at Perl, but I'm less than a novice at
Javascript. I was hoping that if someone had an exmple of this, they
could put it up and explain it to me........

Thanks,

Arthur
 
J

jshanman

Hi All,

I have a form that uses Javascript to validate some fields. Whe the
user selects to submit the form with certain values selected, I want to
be able to execute a Perl script, query the MySQL database to get my
resuts and return an ALERT box to the user if his form input was
invalid.

Problem is, I do not want to change the screen. I just want the dialog
to pop up. I am very good at Perl, but I'm less than a novice at
Javascript. I was hoping that if someone had an exmple of this, they
could put it up and explain it to me........

Thanks,

Arthur


You would need to use XmlHTTPRequest to send all the form fields to a
perl page that can check the input against the database/validation
functions, and either return OK to submit, or return false for a
particular field name/number. This is also known as AJAX.
http://www.w3schools.com/xml/xml_http.asp

Or instead of doing all the form fields at once, you could to the
validation onblur for each form field. However, if the server response
is slow, this will probably be annoying.
 
R

Randy Webb

jshanman said the following on 1/30/2006 3:01 PM:
You would need to use XmlHTTPRequest to send all the form fields to a
perl page that can check the input against the database/validation
functions, and either return OK to submit, or return false for a
particular field name/number. This is also known as AJAX.
http://www.w3schools.com/xml/xml_http.asp

Why do people continue to make the mistake of thinking that
XMLHTTPRequest is the only way to do that? It's not. It is also not the
most widely supported way of doing it. One simple solution that comes to
mind is to submit a dummy form in a hidden IFrame and read the results
back from there.
 
J

jshanman

Randy said:
jshanman said the following on 1/30/2006 3:01 PM:

Why do people continue to make the mistake of thinking that
XMLHTTPRequest is the only way to do that? It's not. It is also not the
most widely supported way of doing it. One simple solution that comes to
mind is to submit a dummy form in a hidden IFrame and read the results
back from there.

Your right, its not the only way. Another way is outline in the
article linked below, which involved appending a child script that is
generated by a server page. The author claims that this is more
compatible then XmlHTTPRequest, however, it only supports GET requests.
Interesting technique, at least.

http://www.phpit.net/article/ajax-php-without-xmlhttprequest/
 
R

Randy Webb

jshanman said the following on 1/31/2006 9:07 AM:
Your right, its not the only way. Another way is outline in the
article linked below, which involved appending a child script that is
generated by a server page.

Yes, and that page doesn't have a real good example of how to load
script files dynamically.
The author claims that this is more compatible then XmlHTTPRequest,

It is - when coded properly.
however, it only supports GET requests.
Ayup.

Interesting technique, at least.

http://www.phpit.net/article/ajax-php-without-xmlhttprequest/

Been doing that new "trick" for several years now.
 
J

jshanman

Randy said:
jshanman said the following on 1/31/2006 9:07 AM:

Yes, and that page doesn't have a real good example of how to load
script files dynamically.


It is - when coded properly.


Been doing that new "trick" for several years now.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Been doing that new "trick" for several years now.
You've also probably been programming for longer then I've been alive
:)

I've never used the iFrame method, but I've done a few tests to compare
the appendChild and XMLHttpRequest, which turned out to be equally
efficient for GET requests.

In your opinion, which way is better, the iframe, appendChild, or
XMLHttpRequest?
 
R

Randy Webb

jshanman said the following on 2/1/2006 8:47 AM:
Randy Webb wrote:

You've also probably been programming for longer then I've been alive
:)

I've never used the iFrame method, but I've done a few tests to compare
the appendChild and XMLHttpRequest, which turned out to be equally
efficient for GET requests.

Did you test it in browsers that do not support XMLHTTPRequest? One
scenario that comes to mind is IE with ActiveX disabled but Scripting
enabled.
In your opinion, which way is better, the iframe, appendChild, or
XMLHttpRequest?

The IFrame is the most reliable and cross-browser if you are wanting to
do POST and GET's with Forms.

But it all goes back to what you are trying to accomplish. But to use
"AJAX" simply so you can say "Hey, I use AJAX" isn't using much brain
power.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top