Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2009, 09:11 PM   PM User | #1
cd_gary
New Coder

 
Join Date: Aug 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
cd_gary is an unknown quantity at this point
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);
cd_gary is offline   Reply With Quote
Old 09-16-2009, 06:07 PM   PM User | #2
ohgod
Regular Coder

 
ohgod's Avatar
 
Join Date: Jun 2008
Location: Ohio
Posts: 579
Thanks: 6
Thanked 69 Times in 69 Posts
ohgod is on a distinguished road
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.
ohgod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:08 AM.


Advertisement
Log in to turn off these ads.