javascript message

Last post 01-09-2009 10:48 AM by NC01. 18 replies.

Sort Posts:

  • Re: javascript message

    01-08-2009, 10:42 AM
    • All-Star
      75,939 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 14,161
    • TrustedFriends-MVPs

    Been a while since I did any regular HTML, but try this.

    Remove the action attribute from the form tag:
    <form method="post" id="formRtwUk">

    and set it dynamically in the validation routine only if validation passes:
    <script type="text/javascript">
    <!--
    function validateForm(elementRef)
    {
     elementRef.disabled = true;

     var textBoxRef = document.getElementById('txtLastName');

     if ( textBoxRef.value.length <= 0 )
     {
      var errorSpanRef = document.getElementById('check_lastname');
      errorSpanRef.innerHTML = 'Please enter last name';
      textBoxRef.focus();
      textBoxRef.select();
      elementRef.disabled = false;

      return false;
     }

     var formElementsArray = document.getElementsByTagName('FORM');

     if ( formElementsArray != null )
     {
      var formElement = formElementsArray[0];
      formElement.action = 'UK-RTW-confirmation.html';
      formElement.submit();
     }

     return true;
    }
    // -->
    </script>

    NC...

  • Re: javascript message

    01-08-2009, 11:05 AM
    • Member
      17 point Member
    • alexASP.NET
    • Member since 11-19-2008, 2:26 PM
    • Posts 127

     Hi thanks for getting back to me,

     

    I'll have a go with that!

     

    Can you just explain to me the significance and the use of the (elementRef) in the function name?

    what if i was to put (formname) in there instead as i have seen that on some other validation forms.

     

    Thank you very much

  • Re: javascript message

    01-08-2009, 11:31 AM
    • Member
      17 point Member
    • alexASP.NET
    • Member since 11-19-2008, 2:26 PM
    • Posts 127

     Hi thats starting to work, thank you!

     

    As its a function that is checking the whole form, I want it to run through all the checks and display them on the screen... which it is doing.

    however at the moment if it does pass the validation it isnt allowing the user to submit.

     

    Is there a way of doing an if statement at the end of the function where (create a variable called errorNote and set it to false at the start then if it false anywhere set it to true.

    If (errorNote = false){

    return true;

    } else if (errorNote = true)

    return false;

    }

     

    Then in the validation checks...

     

    if (IsNumeric(budgetID.value) == false) {
            document.getElementById('check_Budget').style.display = 'block';
            errorNote = true;
        }
        else {
            document.getElementById('check_Budget').style.display = 'none';
            errorNote = false;
        }

     

    but it doesnt seem to be working at the moment...?

     

  • Re: javascript message

    01-09-2009, 10:48 AM
    Answer
    • All-Star
      75,939 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 14,161
    • TrustedFriends-MVPs

    See if this is what you want.

    <form id="form1" name="form1" method="post">
     <input type="text" id="TextBox1" />&nbsp;&nbsp;<span id="TextBox1Span" style="color:Red;"></span>
     <br />
     <input type="text" id="TextBox2" />&nbsp;&nbsp;<span id="TextBox2Span" style="color:Red;"></span>
     <br />
     <input type="submit" onclick="return validatePage(this);" value="Submit" />
    </form>

    <script type="text/javascript">
    <!--
    function validatePage(elementRef)
    {
     elementRef.disabled = true;

     var focusElement = null;
     var textBox1Ref = document.getElementById('TextBox1');
     var textBox2Ref = document.getElementById('TextBox2');

     var textBox1SpanRef = document.getElementById('TextBox1Span');
     var textBox2SpanRef = document.getElementById('TextBox2Span');

     textBox1SpanRef.innerHTML = '';
     textBox2SpanRef.innerHTML = '';

     if ( textBox1Ref.value.length <= 0 )
     {

      textBox1SpanRef.innerHTML = 'Please enter something in TextBox #1';
      focusElement = textBox1Ref;
     }

     if ( textBox2Ref.value.length <= 0 )
     {
      textBox2SpanRef.innerHTML = 'Please enter something in TextBox #2';

      if ( focusElement == null )
       focusElement = textBox2Ref;
     }

     if ( focusElement == null )
     {
      submitForm('UK-RTW-confirmation.htm');
      return true;
     }
     else
     {
      focusElement.focus();
      focusElement.select();
      elementRef.disabled = false;

      return false;
     }
    }

    function submitForm(actionUrl)
    {
     var formElementsArray = document.getElementsByTagName('FORM');

     if ( formElementsArray != null )
     {
      var formElement = formElementsArray[0];
      formElement.action = actionUrl;
      formElement.submit();
     }
    }
    // -->
    </script>

    NC...

Page 2 of 2 (19 items) < Previous 1 2