#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,003
    Rep Power
    376

    Using change function for everything except one element!


    I have form fields, and for each of them i want to invoke a change function except for if the field is expecting "time". This is because this field has been assigned a widget which pops up box with time

    (see http://trentrichardson.com/examples/timepicker/ )

    When I choose a time (change hour/time slidebars) the change function constantly gets invoked which I do not want. so i tried doing:

    Code:
              if ( $(this).attr("class").match(/time/) &&
                   $("#ui-datepicker-div").css("display") == "block"
                 ) {
                        return false;
                    }
    this seem to work, but when i close the pop up box, the change function doesnt get invoked..

    [code]
    <script>
    $(document).ready(function(){

    $(".fields").change( function (e) {

    if ( $(this).attr("class").match(/time/) &&
    $("#ui-datepicker-div").css("display") == "block"
    ) {
    return false;
    }

    ... some more code

    });
    });

    </script>
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    The main thing is jQuery provides a better way to check if an element is visible or not.

    The second thing is that you should avoid using a regex method if you're only searching for a static string.
    Code:
              if ( $(this).attr("class").indexOf('time')!=-1 &&
                   $("#ui-datepicker-div").is(":visible")
                 ) {
                        return false;
                    }
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,003
    Rep Power
    376
    weird, i thought i had replied to this earlier on.

    Thanks for your help, that didnt solve the problem. I placed an "alert" within the if statement and added else { alert...} this never gets fired when the pop up box closes..

    I am going to PM you my url as it is incomplete and I dont want everyone to see it i.e. in terms of security holes etc.

IMN logo majestic logo threadwatch logo seochat tools logo