0

Good Morning.

I am working on button click counter using javascript function. The tricky thing is button type is submit, so page is reloaded whenever I click this button .

Here is the code which include the button.

<div class="skip">
<form method="post" >
<input type="hidden" id="skip_tinv" name="skip_tinv" value=""></input>
<button class="skip" type="submit" value="8" name="submit" onclick="skipCounter();">Skip >></button>
<?php include('includes/aftersubmit.php'); ?>         
</form>

I have ten of this form in one page(which means ten of skip button in one page), and I want this "skip" button is disabled when it clicked more than three times. Do you have any idea of this?

The idea using php is also welcomed. Thank you for your help.

Taewan
  • 1,167
  • 4
  • 15
  • 25

1 Answers1

0

You can use jQuery - Prevent Default or Javascript - Prevent Default This will stop the submit button from reloading the page and you can keep track of how many times the buttons were clicked. Once that counter gets above 3 then use jQuery/javascript to hide the skip button

Community
  • 1
  • 1
immulatin
  • 2,118
  • 1
  • 12
  • 13
  • Thanks. The problem is "reloading" the page is necessary in current code. Because this is php file and I need to call another php function in the same page. Anyway to make counter with reloading the page? seems I have to use php instead of javascript? – Taewan Jun 13 '13 at 14:40
  • Yeah that is true because javascript will lose its state on refresh. You could repopulate the javascript counter variables with PHP. Say store the counter in a get variable myurl.com/page.php?counter=4 or store the counter in a cookie/session variable – immulatin Jun 13 '13 at 14:42
  • Right. Sounds like that's the way. Thanks – Taewan Jun 13 '13 at 14:44