Jump to content

Javascript wont allow script to refresh


SirChick

Recommended Posts

Hey guys, I'm some what new to javascript so bare with me...

 

I currently have submit button which can be pressed once every 3 seconds. So it disables it counts to 3 then allows it again.

 

How ever this button when pressed needs to refresh the php page but the javascript is not allowing that to happen thus the form submit doesn't occur when pressed but the javascript runs every time.

 

Is there a way to add a refresh prior to the count so the form will submit and the count also work?

 

Here is what i have:

<script type="text/javascript">
var c=0
var t

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
if (c>=4)
{
setTimeout("stopCount()");
}
t=setTimeout("timedCount()",1000);
}

function stopCount()
{
clearTimeout(t);
x="Submit";
c=0;
document.getElementById('txt').value=x;
}
</script>

 

In the form I have:

 

<center>
<form name="" method="POST" action="attack.php">
<input type="Button" id="txt"  name="submit" value="Submit" onClick="timedCount()">
</form>
</center>

Link to comment
https://forums.phpfreaks.com/topic/117176-javascript-wont-allow-script-to-refresh/
Share on other sites

Well, it sounds as though, if you're wanting your page to refresh when the button is clicked, your logic should be such that when the page refreshes, the button is inactive for three seconds. That way, when it is clicked and the form is submitted, it is automatically disabled for three seconds on page load again. I would try something like this:

var c = 0;

function setWait()
{
  var btn = document.getElementById('txt');
  if (c < 3)
  {
    btn.disabled = true;
    btn.value = 'Wait... ' + c;
    c++;
    setTimeout(setWait, 1000);
  }
  else
  {
    btn.disabled = false;
    btn.value = 'Attack!';  
  }
}

window.load = function()
{
  setWait();
}

 

Hope that helps.

Hmm that doesn't allow the page to refresh either.. do i have to change the submit button's html info to anything different?

 

Heh... yea, my code is assuming your button is a submit type:

<input type="submit" name="submit" value="Submit" />

Hmm that doesn't allow the page to refresh either.. do i have to change the submit button's html info to anything different?

 

Heh... yea, my code is assuming your button is a submit type:

<input type="submit" name="submit" value="Submit" />

 

It is a submit type i changed it, though the page now refreshes the button itself doesn't count.

 

This is what I have:

 

 

JS:

var c = 0;
function setWait()
{
  var btn = document.getElementById('txt');
  if (c < 3)
  {
    btn.disabled = true;
    btn.value = 'Wait... ' + c;
    c++;
    setTimeout(setWait, 3000);
  }
  else
  {
    btn.disabled = false;
    btn.value = 'Attack';  
  }
}

window.load = function()
{
  setWait();
}

 

The form:

	<center>
<form name="" method="POST" action="attack.php">
<input type="Submit" id="txt"  name="attack" value="Attack">
</form>
</center>

This is pretty much the same as Obsidian's code, but I tested it and it works fine.

<html>
<head>
<script language="JScript">
var c=3;
function setWait()
{
if (c)
{
	frm1.btn.value="Wait..."+c;
	c--;
	setTimeout("setWait()", 1000);

}
else
{
	frm1.btn.disabled=false;
	frm1.btn.value="Attack!";
}
}
</script>
</head>
<bodY onload="setWait()">
<form id="frm1">
<input type="submit" id="btn" disabled="true">
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.