...

View Full Version : Prototype Prototype Form Validation Not Working Currectly



cd_gary
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

HTML

<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:

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);

ohgod
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum