SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding onchange event to Mootools datepicker

    I have a datepicker field setup like this and it works fine:

    <input
    readonly='readonly'
    name='newInternalDate'
    id='newInternalDate'
    type='text'
    value='<?php echo $perfdate;?>'
    class='date date_toggled order_date'
    style='background-color:rgb(210,255,210);width:85px;'
    />
    I would like to raise an alert when the value is changed. I've added this:
    <input
    ..........
    onchange='alert("here");'
    />
    but it doesn't work. Anyone know how to make it work please?
    Thanks

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,112
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this makes a difference, but you have the input marked readonly, so it should never change (which maybe why your alert isn't getting invoked)

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Not sure if this makes a difference, but you have the input marked readonly, so it should never change (which maybe why your alert isn't getting invoked)
    Thanks. I removed that line and it makes no difference. Actually the fact that it's marked readonly doesn't mean it can't change, only that it can't be changed in the usual way of typing something into the box. It can still be changed by JS or php.

  4. #4
    SitePoint Enthusiast OMGCarlos's Avatar
    Join Date
    Apr 2012
    Location
    Boston, MA
    Posts
    91
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It can't be changed with PHP in a way that would trigger the onchange event, it'll always have to be triggered via Javascript.

    Even then, changing the value of an input box programmatically won't actually trigger the onchange event...I know, weird. Wherever you're changing the value in your script, add:
    Code:
    document.getElementById('newInternalDate').onchange();
    or if you're using jQuery:
    Code:
    $('#newInternalDate').change();
    Demo: http://jsfiddle.net/pAkx8/
    Uncomment the javascript line to see the alert message.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •