The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript help with creating validation plugin

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #39857

    This is my first time creating a plugin.I am trying to make a plugin that will validate whether input field is emty or not.
    My problem is with keyup() function if I call it as I did in 1.php it works fine, but I want to put keyup() in plugin as I did in vall.js, it is commented out $(this).keyup(function() it is not working. Should I place keyup() somewhere else or make a separate keyup() function.
    Later I want to add keyup(),focus()… to options so I can just write keyup:true or something like that.
    Thank you
    this is val.js

    ( function($){

    $.fn.validation = function(options) {

    var settings= {required: '',rqrmsg:''};

    if(options){$.extend(settings, options); }
    var options = $.extend(settings, options);

    // $(this).keyup(function() {

    if(options.required == 'true') {
    var error = 0;
    var elem1 = $(this).val();
    if (elem1 == '') {
    error = 1;
    this.css({'border':'Solid 1px Yellow','background-color':'red'}).next().fadeIn('fast').text(options.rqrmsg)


    $(this).css({'border':'Solid 1px Yellow','background-color':'green'}).





    this is where I am calling the main jquery file

    < script src="">
    < script src="val.js">

    <form id='targets' name='targets' action='' method='post' >
    <span class="">Email</span>
    <input type='text' name='test' id='email' /><span class="error"></span> </br>
    <input type='text' name='test1' id='miho' /><span class="error"></span> </br>
    <input type='submit' value='Save' id='save'/>

    < script>
    $(document).ready(function() {
    $('#email').keyup(function() {

    $('#miho').keyup(function() {


    < /script>

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.