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
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.

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.