Results 1 to 4 of 4

Thread: Button to call JS

  1. #1
    Join Date
    Aug 2007
    Location
    Ft Myers, FL
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Button to call JS

    I used to have a function call on a regular submit button, but changed it to a image type, but the call does not appear to work anymore.

    It just seems to submit right though when it should not.


    Code:
    <input type="image" name="No Addendum Required" class="Addendum_btn" src="images/buttons/no_addendum_required.png" alt="No Addendum" width="100" height="100" border="0" onClick="return validateNoAddendumRequired()">
    here is the JS function

    Code:
    function validateNoAddendumRequired() {
       var ta = frmAddendum.elements["Addendum"];
       clearComments(document.frmAddendum.Addendum);   
    
       if (!ta.value.length) {
          //alert("You must enter your text or choose No Addendum Required.");
          return true;
       }
       else
       {
        return (confirm("You have chosen to enter a comment.  This will not become part of the medical record."));
       }
    }
    Here is the previous button code.


    Code:
    <input name="btnSubmit" type="submit" id="btnSubmit" class="button" value="No Addendum Required" onClick="return validateNoAddendumRequired()">

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Use the onsubmit event:

    <form ........... onsubmit="return validateNoAddendumRequired()">

  3. #3
    Join Date
    Aug 2007
    Location
    Ft Myers, FL
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have 3 buttons on this form, and 2 of them need to perform different validation.

    Any ideas on how i Can fix this? Do i need on validation function that is run onSubmit? But is there a way to tell which button is clicked?

    Code:
    
    <form action="page.asp" method="post" name="frmAddendum">
    
    
    <textarea name="Addendum" cols="47" rows="10" onClick="clearComments(document.frmAddendum.Addendum)"><%=Addendum%></textarea>  
    <table>
    <tr>
        <td><input type="image" name="No_Addendum_Required" class="Addendum_btn" src="images/buttons/no_addendum_required.png" alt="No Addendum" width="100" height="100" border="0" onClick="return validateNoAddendumRequired()"></td>
        <td><input type="image" name="Save_Complete_Later" class="Addendum_btn" src="images/buttons/save_addendum_complete_later.png" alt="Save Addendum for Later" width="100" height="100" border="0"></td>
        <td><input type="image" name="Electronic_Signature" class="Addendum_btn" src="images/buttons/save_addendum_signature.png" alt="Save and Sign" width="100" height="100" border="0"  onClick="return validateElectronicSignature()"></td>
    </tr>
    </table>
    </form>

    Code:
    function validateElectronicSignature() {
       var ta = document.frmAddendum.elements["Addendum"];
       clearComments(document.frmAddendum.Addendum);   
    
       if (!ta.value.length) {
          alert("You must enter your text or choose No Addendum Required.");
          return false;
       }
       return (confirm("By signing this addendum your statements will become part of the medical record."));
    }
    
    
    function validateNoAddendumRequired() {
       var ta = document.frmAddendum.elements["Addendum"];
       clearComments(document.frmAddendum.Addendum);   
    
       if (!ta.value.length) {
          //alert("You must enter your text or choose No Addendum Required.");
          return true;
       }
       else
       {
    	return (confirm("You have chosen to enter a comment.  This will not become part of the medical record."));
       }
    }

  4. #4
    Join Date
    Aug 2007
    Location
    Ft Myers, FL
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Or would it be better to add the form submit to my existing functions, and just make the images links that call the JS i want to run?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •