...

View Full Version : Resolved validation sample snippet?



capt_nemo777
12-07-2010, 03:10 AM
hi,

I have a form in my mvc



<h1>Update Password <?php echo $model->MemberShipID; ?></h1>
<div class="form">
<?php echo CHtml::beginForm(array('id'=>'updatepwd')); ?>
<?php echo CHtml::errorSummary($model)?>

<div class="row">
<?php echo CHtml::activeLabelEx($model,'WSLoginPassword'); ?>
<?php echo CHtml::activePasswordField($model,'WSLoginPassword',array('size'=>20,'maxlength'=>50,'id'=>'pwd')); ?>
<?php echo CHtml::error($model,'WSLoginPassword'); ?>
</div>

<div class="row">
<?php echo CHtml::activeLabelEx($model,'Retype Password'); ?>
<?php echo CHtml::activePasswordField($model,'WSLoginPassword_repeat',array('id' => 'retypepwd')); ?>
</div>

<div class="action">
<?php echo CHtml::submitButton('Update'); ?>
</div>

<?php echo CHtml::endForm(); ?>


can someone give me a snippet how to use jquery to do the validation on this once the submitButton is clicked, it will check if

- the 'pwd' field is empty and cannot be empty
- the 'retypepwd' field should be exactly the same as the 'pwd' field and cannot be empty
:confused:

Spudhead
12-07-2010, 12:17 PM
Post the generated client-side HTML, not the raw server-side PHP.

capt_nemo777
12-08-2010, 08:05 AM
problem solved, I only know the basic of jquery, but somehow it works, thanks for the reply



<script>
$(document).ready(function(){
$('#updatepwd').submit(function(){
if($('#pwd').val() == 0){
alert('password cannot be empty');
return false;
}
if($('#retypepwd').val() == 0){
alert('retype password cannot be empty');
return false;
}
if($('#retypepwd').val() !== $('#pwd').val()){
alert('retype password must be the same with first field');
return false;
}
});
});
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum