Validation function problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    Validation function problem.

    I've a function that validate a form field:

    <html>
    <head>
    <script language="JavaS cript">
    function CheckFields(For mSubmit,BtnName )
    {
    if (BtnName!="Canc el")
    {
    check = true;
    if (FormSubmit.Use r_Account.value == ""){
    alert ("Username compulsory");
    FormSubmit.User _Account.focus( );
    return false;
    }....

    My FORM:
    <form action="<?php echo $editFormAction ; ?>" name="formSubmi t"
    method="POST"> <!--form action myself-->
    ....
    <input type="submit" name="SubmitBut ton" value="Add"
    onClick="CheckF ields(this.form , this.value)">
    &nbsp;<input type="submit" name="SubmitBut ton" value="Cancel">

    Now, if I click on cancel, I do redirect (with PHP) to a previous page. If I
    click on Add, a check is done on the compulsory fields. I would like the
    focus on the selected field (the one that isn't right), but the form is
    reloaded. How to avoid this ?

    I've tried to put the check on the form.OnSubmit (that fires before I submit
    the form, and set the buttons input type as "button" instead of "submit"),
    instead of the button click (that does submit the form), but I can't
    retrieve with button was pushed. (I've tried FormSubmit.Subm itButton.name,
    but it doesn't work)

    Please help.


  • Eric Bohlman

    #2
    Re: Validation function problem.

    "Bob Bedford" <bedford1@YouKn owWhatToDohotma il.com> wrote in
    news:3fbfe3c3$0 $3235$5402220f@ news.sunrise.ch :
    [color=blue]
    > <input type="submit" name="SubmitBut ton" value="Add"
    > onClick="CheckF ields(this.form , this.value)">
    > &nbsp;<input type="submit" name="SubmitBut ton" value="Cancel">
    >
    > Now, if I click on cancel, I do redirect (with PHP) to a previous
    > page. If I click on Add, a check is done on the compulsory fields. I
    > would like the focus on the selected field (the one that isn't right),
    > but the form is reloaded. How to avoid this ?[/color]

    Your event handler needs to *return* the value from CheckFields:
    onClick="return Checkfields..."

    Comment

    • Bob Bedford

      #3
      Re: Validation function problem.

      Thanks Eric...it was that simple !!!

      Regards

      "Eric Bohlman" <ebohlman@earth link.net> a écrit dans le message de
      news:Xns943BAD7 5C490Cebohlmano msdevcom@130.13 3.1.4...[color=blue]
      > "Bob Bedford" <bedford1@YouKn owWhatToDohotma il.com> wrote in
      > news:3fbfe3c3$0 $3235$5402220f@ news.sunrise.ch :
      >[color=green]
      > > <input type="submit" name="SubmitBut ton" value="Add"
      > > onClick="CheckF ields(this.form , this.value)">
      > > &nbsp;<input type="submit" name="SubmitBut ton" value="Cancel">
      > >
      > > Now, if I click on cancel, I do redirect (with PHP) to a previous
      > > page. If I click on Add, a check is done on the compulsory fields. I
      > > would like the focus on the selected field (the one that isn't right),
      > > but the form is reloaded. How to avoid this ?[/color]
      >
      > Your event handler needs to *return* the value from CheckFields:
      > onClick="return Checkfields..."[/color]


      Comment

      • Matthias H. Risse

        #4
        Re: Validation function problem.

        in case you have a lot of forms to implement
        and a lot of rules to follow or fields to validate
        you shoudl check out PEAR:HTML_Quick Form.

        it also supports client-side validation via
        auto-generated or customly written javascript
        functions.



        Comment

        Working...