0

I have a input text box. After the user is idle from typing I want it to submit the form(which works in the below code) and a image of a checkmark to popup then fadeout. I was just trying to test the fadeout function so the img is visible but I can't seem to get it to work.

var timer = null;
$('.form_timer').keyup(function()
{
    if (timer) {
        clearTimeout(timer);
    }

    var test = $(this);
    timer = setTimeout(function() {
        test.next('img').fadeOut('slow');
        test.closest('form').submit();

    }, 700);
});

:EDIT#1 Markup

<div class="accordion">
    <div class="group">
        <form accept-charset="UTF-8" action="/tasks/2" class="simple_form edit_task" data-remote="true" id="edit_task_2" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="Fil9PitLB6ZhHtWwBOehbOBkq2yE6qikN5cU0zr4wRQ=" /></div>
            <h3><div class="input string optional"><label class="string optional control-label" for="name_2">Task Name</label><input class="string optional form_timer" id="name_2" name="task[name]" placeholder="New Task" size="50" type="text" value="somethingdd" /></div></h3>
            <div>
                <div class="input string optional" style="display: inline"><label class="string optional control-label" for="description_2">Description</label><input class="string optional form_timer" id="description_2" name="task[description]" size="50" type="text" value="blah123asdfgokkkkkasddadsdd" /></div><img alt="checkmark" class="form_checkmark" height="20px" src="/assets/checkmark.jpg" width="20px" />
            </div>
        </form>
    </div>
</div>        
Sinble
  • 310
  • 1
  • 2
  • 9

2 Answers2

0

With this markup

<form method="get">
    <textarea class="form_timer">type in here</textarea>
    <img src="" width="200" height="150" style="display:block;background:#0c0;"/>
</form>​

your code works fine. Test it yourself here http://jsfiddle.net/bukfixart/AvsUH/

bukart
  • 4,906
  • 2
  • 21
  • 40
0

Updated my code to use parent then next. Seems .next works differently then I expected. I still don't like this as a solution because the textfield could possibly be two levels deep in divs or etc...

var timer = null;
$('.form_timer').keyup(function()
{
    if (timer) {
        clearTimeout(timer);
    }

    var test = $(this);
    timer = setTimeout(function() {
        test.parent().next('.form_checkmark').fadeOut('slow');
        test.closest('form').submit();

    }, 700);
});

EDIT#1 Did some more digging Doesn't look like there is a easy solution for what I wanted. Found a solution someone else posted after I knew what i was looking for. Found here

Community
  • 1
  • 1
Sinble
  • 310
  • 1
  • 2
  • 9