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

Discussion in 'Javascript' started by amerar@iwc.net, Jan 30, 2006.

  1. Guest

    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
     
    , Jan 30, 2006
    #1
    1. Advertising

  2. jshanman Guest

    wrote:
    > 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.
     
    jshanman, Jan 30, 2006
    #2
    1. Advertising

  3. Randy Webb Guest

    jshanman said the following on 1/30/2006 3:01 PM:
    > wrote:
    >> 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


    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.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Jan 30, 2006
    #3
  4. jshanman Guest

    Randy Webb wrote:
    > jshanman said the following on 1/30/2006 3:01 PM:
    > > wrote:
    > >> 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

    >
    > 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.
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


    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/
     
    jshanman, Jan 31, 2006
    #4
  5. Randy Webb Guest

    jshanman said the following on 1/31/2006 9:07 AM:
    > Randy Webb wrote:
    >> jshanman said the following on 1/30/2006 3:01 PM:
    >>> wrote:
    >>>> 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

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


    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.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Feb 1, 2006
    #5
  6. jshanman Guest

    Randy Webb wrote:
    > jshanman said the following on 1/31/2006 9:07 AM:
    > > Randy Webb wrote:
    > >> jshanman said the following on 1/30/2006 3:01 PM:
    > >>> wrote:
    > >>>> 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
    > >> 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.

    >
    > 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.
    >
    > --
    > 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?
     
    jshanman, Feb 1, 2006
    #6
  7. Randy Webb Guest

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


    <snip>

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

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


    <shrug> Possibly.

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

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Feb 2, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H.MuthuKumaraRajan
    Replies:
    3
    Views:
    490
    H.MuthuKumaraRajan
    Feb 4, 2004
  2. chlori
    Replies:
    11
    Views:
    5,996
    Lauri Raittila
    Feb 11, 2005
  3. xkenneth
    Replies:
    8
    Views:
    367
    Bruno Desthuilliers
    Feb 6, 2008
  4. Atemporal
    Replies:
    8
    Views:
    317
    Atemporal
    Mar 29, 2008
  5. Replies:
    5
    Views:
    86
Loading...

Share This Page