JavaScript example - validation

Validating on submit

This is just what I am looking for. I set up two email fields which must match. This works fine, except you can tab through it to go to the next fields. I was looking for a script that would check those email addresses again to see if they match. Now... I placed it in components/com_fabrik/js folder, but how do it attach it to the form?

---

Here's my script 33.js

function watchSubmit(e){
// Select the Submit button and bind our submitMyForm() to the 'click' event.
// Would need to be a bit more selective about this if more than one form
var submit_button = $E('input[name=Submit]');
if (submit_button) {
submit_button.addEvent('click', function(e){
e = new Event(e);
e.stop();
submitMyform('');
}.bind(this))
}
}

function submitMyform() {
// We get called from the click event handler.
// Do the form validation, only call form.submit() if it passes all tests.
// First the regexp we use for validating the characters used in the username
var r = new RegExp("[\<|\>|\"|'|\%|\;|\(|\)|\&|\+|\-]", "i");
// select the form ... it'll always be fabrikXX, where XX is your form ID.
var form = $E('form[name=fabrik33]')
// now do all the validations
if (trim(form.comom_reg2010___email1.value) != "" && form.comom_reg2010___email1.value != form.comom_reg2010___email2.value){
alert( "Email Addresses do not match." );
} else {
// whoop whoop! we passed all validations, so submit the form.
form.submit();
}
// if we get here, we failed validation, so don't do nuffink
return false;
}

Window.onDomReady(function(){
// invoke the watchSubmit function just once when the page loads
// this will bind our submitMyForm function to the Submit button
watchSubmit();
})

Your instructions are always greatly appreciated.

Thanks
JPL
 
Hmmm, I wrote that script quite some time ago, and from looking at it, I don't think it will work as-is, as we have changed the way forms get submitted.

I'll have to do some testing and get back to you.

-- hugh
 
HI
,
this is archana.Actually i am new to Joomla 2.5 and i have just created dummy form through fabrick. There is a tab for javascript validation under FORM' FIELD ELEMENT:EDIT section.
I want to validate that this element should not be blank. I know there is plugin for it but i want to write JS CODE as i do not know how it is implemented under this tab...

Please anyone one can help me then please help me...Please help..Please...
IF u can send some simple example code then it will be also better...
My id is archanazohns@gmail.com
 
Have you tried just using a normal Validation on the element (there is a "not empty" validation), and setting "AJAX Validation" on your Form settings?

That should achieve the same effect as writing your own JS to do it.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top