admin管理员组

文章数量:1426931

How do I reload this input once after 3 seconds has passed after the webpage has loaded. using javascript

<input type="text" name="steamID" id="steamID" value="<?php echo $steamid; ?>">

How do I reload this input once after 3 seconds has passed after the webpage has loaded. using javascript

<input type="text" name="steamID" id="steamID" value="<?php echo $steamid; ?>">
Share Improve this question edited Nov 30, 2012 at 20:01 Beska 12.7k14 gold badges80 silver badges113 bronze badges asked Nov 30, 2012 at 19:55 Hannes Brolin LagerstedtHannes Brolin Lagerstedt 874 silver badges12 bronze badges 2
  • 2 Are you using any Javascript frameworks like jQuery, Prototype, or MooTools? – Eric Commented Nov 30, 2012 at 20:01
  • 1 Please check this answer: stackoverflow./a/4671060/563049 – Andrey Rudenko Commented Nov 30, 2012 at 20:02
Add a ment  | 

4 Answers 4

Reset to default 4

Try looking at this answer on SO:

Reload random div content every x seconds

If that doesn't work for you, you will have to use ajax to get new content. Look at jQuery's API here:

http://api.jquery./jQuery.ajax/

Or if you're not using jQuery, look at this for a tutorial on AJAX:

http://www.w3schools./ajax/default.asp

Otherwise, for more help, please post more of your code -- but ajax will have to be used

If you want the PHP in your code to be run again, you need to make you code a little more plicated.

You will need the following ponents

  1. a php file that will lookup and print $steamid only.

  2. a javascript function that uses AJAX to get the information from the php file, sets the value of your input

  3. call the javascript on page load, then set an interval for 3 seconds and call it again.

But based on this...

The problem i have that the PHP var $steamid are set after the input has been created so all i need todo is reload the input so the $steamid will show.

... I think you just need to re-order your PHP code.

By reset, I am assuming you mean set the value to null.

$(window).load(function(){
   setTimeout( function() { 
    document.getElementById("steamID").value = "";
    },3000);
});

EDIT: Based on your further description, wait until steamID is set, then put this on the page:

<script type="text/javascript">
  document.getElementById("steamID").value = "<?php echo $steamid; ?>";
</script>
<?php
    echo "<script type='text/javascript'>";
    $steamid = "testing 1,2,3";
    echo "    var sID = '".$steamid."';";    
?>
    function setupRefresh() {
       setInterval("refreshVal()", 3000);
    }
    function refreshVal() {
       var e = document.getElementById('steamID');
       e.value = sID;   
    }
</script>

本文标签: phpHow do I reload a input after 3 seconds with javascriptStack Overflow