Hendrix
Hendrix

Reputation: 179

The reset button does not work textarea

I have the following code does not work when I click on reset.

For some strange reason when does the process of generating the values in the "results" field and I click on "reset" does not clear the field "enter".

EXAMPLE: http://jsfiddle.net/Ljsp6Lv6/1/

HTML:

<h3>Enter:</h3>
<textarea value="" id="enter"></textarea>
<div id="hide">
    <h3>Result:</h3>
    <textarea class="disable" id="result"></textarea>
    <br />
    <input type="reset" value="Reset" class="button reset" />
</div>

JS:

$('#enter').keyup(function () {
    var eachLine = $(this).val().split('\n');
    var result='';
    console.log(eachLine);
    for(var i=0;i<eachLine.length;i++){
        var url = 'http://www.domain.com/myimages/' + eachLine[i] + '/' + eachLine[i] + '_small.jpg';
        result = result + url + '\n';
    }
    $('#hide').show();
    $('#result').html(result);
});

Upvotes: 0

Views: 703

Answers (1)

adeneo
adeneo

Reputation: 318212

You'll need a form element to make reset work, and that's the answer, wrap everything you want to reset in a form element.

If you want to hide the other textarea as well, add some more jQuery

$('.reset').on('click', function() {
    $('#enter').trigger('keyup');
    $('#hide').hide();
});

FIDDLE

Upvotes: 2

Related Questions