SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    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:

    Code:
            <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>
    Code JavaScript:
            <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.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by wazo View Post
    I hope you can help


    I have a text box which has auto generated text depending on the date selected from the calendar
    Which calendar are you using? Maybe it has some features that we can help you use to achieve what you need to do.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by wazo View Post
    On that page select hte Events tab, and you will see an event called onSelect which is designed to do what you need here.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •