www.webdeveloper.com
Results 1 to 6 of 6

Thread: onchange

  1. #1
    Join Date
    Apr 2005
    Posts
    7

    onchange

    I have two text boxes with diffrent datepicker.
    Txt1: default to the current date. (Required)
    Txt2: user can pick the date from the picker calendar.
    I want the date in txt1 change to the same date from txt2 when user picks the date from the picker.

    How can i accomplish that? Thank you very much.

    Thanks
    Last edited by hongho2; 07-12-2012 at 01:52 PM.

  2. #2
    Join Date
    Jun 2007
    Location
    Winnipeg, MB CANADA
    Posts
    128
    HTML portion:
    Code:
    <input id="txt1" />
    <input id="txt2" onblur="checkValue(this);" />

    Javascript Portion:
    Code:
    <script>
    function checkValue (el){
         if (el.value != ""){
              document.getElementById("txt1").value = el.value;
         }
    }
    </script>

  3. #3
    Join Date
    Apr 2005
    Posts
    7
    i've tried your code but it didn't work, any other sugesstions?
    <script>
    function checkValue (el){
    if (el.value != ""){
    document.getElementById("txt1").value = el.value;
    }
    }
    </script>
    <cfform>
    <cfinput type="datefield" name="txt1" id="txt1" value="" size="12" required="no">
    <cfinput type="datefield" onblur="checkValue(this);" name="txt2" id="txt2" value="" size="12" required="no">

    </cfform>

  4. #4
    Join Date
    Jun 2007
    Location
    Winnipeg, MB CANADA
    Posts
    128
    Works here:
    http://jsfiddle.net/pphresh/AQ3MJ/1/


    the change will occur when you click off the input field. You can also try switching onblur with onchange. It may suit your needs better. try them both.

  5. #5
    Join Date
    Apr 2005
    Posts
    7
    already tried but didn't work

    <script>
    function checkValue (el){
    if (el.value != ""){
    document.getElementById("txt1").value = el.value;
    }
    }
    </script>
    <cfform action="" method="post">
    <cfinput type="datefield" name="txt1" id="txt1" value="" size="12" required="no">
    <cfinput type="datefield" onchange="checkValue(this);" name="txt2" id="txt2" value="" size="12" required="no">
    </cfform>

  6. #6
    Join Date
    Jun 2007
    Location
    Winnipeg, MB CANADA
    Posts
    128
    you're using cold fusion? I'm not sure if these javascripts work in cold fusion. Can you try in regular HTML first to see if it works for you?

    Also try closing the input element <cfinput ... />

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles