Pass value without user clicking away from input type text

Hi guys

I hope you can help

I have a text box which has auto generated text depending on the date selected from the calendar

The problem I have is that I need this value to pass to ajax but as I am not actually entering the text myself I cannot use onChange,onkeydown onkeyup as the
text changes depending on the date chosen from the calendar

The script works fine when i type in the actual text box itself

Is there anyway I could use the functionality of onkeyup or onkeydown without actually entering a value. I want it to update when the text box is updated dynamically?

Thanks in advance

If you can’t edit the calendar code to fire off an ajax function when a new date is selected then one option could be to set up a setInterval to poll the value of the textbox, say every 2 secs, and if the value has changed then fire off an ajax request. Something like this as a starting point:

        <form action="" method="post" >
            <select id="sel1" name="sel1" onchange="doThis(this.value);">
                <option value="">Choose a value</option>
                <option value="val1">Value 1</option>
                <option value="val2">Value 2</option>
                <option value="val3">Value 3</option>
                <option value="val4">Value 4</option>
            </select>
            <input type="text" id="txt1" name="txt1" />
        </form>


        <script type="text/javascript">
            function doThis(val){
                document.getElementById('txt1').value = val;
            }
            function checkVal(elem){
                if(elem.value != elem.prevValue){
                    alert('textbox value has changed');
                    elem.prevValue = elem.value;
                }
            }
            window.onload=function(){
                var txt1obj = document.getElementById('txt1');
                txt1obj.value = '';
                txt1obj.prevValue = ''
                setInterval(function(){checkVal(txt1obj);},2000);
            }
        </script>

The <select> simulates your calendar.

Which calendar are you using? Maybe it has some features that we can help you use to achieve what you need to do.

Hi guys

I am using http://jqueryui.com/demos/datepicker/

On that page select hte Events tab, and you will see an event called onSelect which is designed to do what you need here.