View Full Version : Prototype Prototype Form Validation Not Working Currectly

09-13-2009, 10:11 PM
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


<script type="text/javascript" src="../Javascript/test.js">



<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="entry" method="post">
<h2>Edit Credential Category</h2>
<table id="edit">
<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>
<input name="id" type="hidden" value="<?php echo $id; ?>" /><br/>
<input name="submit" type="submit" value="Edit" />


Prototype Javascript Code:

function submitEntryForm(event)

if ($('credential_cat').value==null||$('credential_cat').value=="")
alert('Must Enter Data');
return false;
return true;


function addOb()
$('entry').observe('submit', submitEntryForm);

Event.observe(window, 'load', addOb);

09-16-2009, 07:07 PM
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.