Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prototype Form Validation Not Working Currectly

    I'm currently using prototype framework to validate whether or not a field is has data. When the field is empty and the user hits the form submit button the intended alert message box comes up, but after you hit OK on the message box it submits the form anyway, which I don't want to happen. Can you help Please

    HTML
    Code:
    <script type="text/javascript" src="../Javascript/test.js">
    
    
    </script>
    
    <body>
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="entry" method="post">
    <h2>Edit Credential Category</h2>
    <table id="edit">
    <table>
    <tr>
    <td><label>Credential Category:</label></td>
    
    <td><input type="text" id="credential_cat" maxlength=40 name="credential_cat" size="40" value="<?php echo $credential_cat; ?>" /></label><br /></td>
    </tr>
    </table>
    <input name="id" type="hidden" value="<?php echo $id; ?>" /><br/>
    <input name="submit" type="submit" value="Edit" />
    
    </form>
    Prototype Javascript Code:
    Code:
    function submitEntryForm(event)
    {
    	
    	
    	if ($('credential_cat').value==null||$('credential_cat').value=="")
    		{
    		alert('Must Enter Data');
    		return false;
    		}else
    		{
    		return true;
    		}	
    		
    }
    
    function addOb()
    {
    	$('entry').observe('submit', submitEntryForm);
    }
    
    Event.observe(window, 'load', addOb);

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    i'm wondering if it might work better if the observer watched for a click on the submit button instead of watching for the form to submit. it might be too late in the process to kill the form's submission.


  •  

    Posting Permissions

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