CodeIgniter Forums
CI and Ajax (prototype) validation - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: CI and Ajax (prototype) validation (/showthread.php?tid=11090)

CI and Ajax (prototype) validation - El Forum - 08-25-2008

Greetings all,

I am rather new to Javascript and Ajax, try as I might to hold onto the server side past I am starting to fall to the Dark Side.

What I am attempting to do is write a validation library for a data gathering application, validate as much data on the client side before submission, thus reduce the number of "opps" page loads. Problem is as it got more complicated it stopped working. Here's what I need to do.

1) Once a form is loaded each field will run a validateField() function to validate it's own data for completion and proper format.

2) When the user clicks the submit button the function validateForm() will run and if there are no errors the form will submit itself, otherwise it will return a message that data was not complete ( which should almost, if ever, happen ).

Now, #1 is trickier than it sounds... My intention is to use the class tag to determine the validations that would run on a particular field ( class="required email" etc), thus allowing me to use addClassName to add additional validations for a field on the fly ( e.g. the value of item #1 means that now there must be a value entered for item #5 & #6, I merely addClassName('required') to the respective items ).

Here is the widget I have thusfar:

function ValidateField(input, container){
    new Ajax.Request('validator.php', {
        parameters: {validation: $F($(input).readAttribute('class')), value: $F(input)},
            onComplete: function(AjaxResult) {
                    $(input).setStyle({border:'1px #C00 solid'});
                } else {
                    $(input).setStyle({border:'1px #0C0 solid'});

Then, for the html markup:

<input type="text" class="required" name="coc" maxlength="10"
value="<?=$this->validation->coc;?>" size="25" onblur="ValidateField(this, 'coc')"/>

At this point in time I think what is not happening is the tag class(es) are not being passed into the validateField function... This was working when I was manually passing in a validation rule for the function, but that prevents me from adding rules on the fly.

Thanks for any help you guys might be able to provide.