james2569
james2569

Reputation: 53

On div refresh text inside the input box shouldn't clear

I have a div and it refreshes every 3 seconds. Inside that div there is an input box and whatever I type gets cleared out in 3 seconds. Is there a way for the text to remain inside the input box and not to get cleared out?

index.js

<div id="show_here"></div>
<script type ="text/javascript">
    $(document).ready(function() {
        setInterval(function() {
            $('#show_here').load('fetch.php')
        }, 3000);
    });
</script>

fetch.php

<div>
     // some code here 
    <input type="text" id="input" />
</div>

Input box needs to be inside that page since it is inside a while loop. Can this be done or i need to change my whole code to make this work?

Upvotes: 1

Views: 82

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133360

Preserve and then set

setInterval(function() {
    my_val = $('#input').val();
    $('#show_here').load('fetch.php');
    $('#input').val(my_val); 
}, 3000);

Upvotes: 2

Related Questions