HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
How to add 1 to a number
Post new topic   Reply to topic    HTML Help Forum Index -> General HTML
View previous topic :: View next topic  
Author Message
dijulio34



Joined: 13 Nov 2008
Posts: 1

PostPosted: Thu Nov 13, 2008 6:34 pm     How to add 1 to a number Reply with quote

Ok basically theres a yes and a no button. when you click yes i want one more yes for the counter. when no i want one more no for the counter Neutral
Straystudio



Joined: 14 Apr 2008
Posts: 264
Location: Nord Italy

PostPosted: Fri Nov 14, 2008 2:14 am     yes/no hits counter Reply with quote

This for a two-fields yes/no total hits counter.
Let me know if You mean something different.
Code:


<html>
<head>
<title>yes/no counter</title>

<script type="text/javascript">

var ycurrlevel = 0;
var ncurrlevel = 0;


function add_yes(){

var ylevel = ycurrlevel +1;
document.getElementById("ytot").value = ylevel;
ycurrlevel = ylevel;
}


function add_no(){

var nlevel = ncurrlevel +1;
document.getElementById("ntot").value = nlevel;
ncurrlevel = nlevel;
}

</script>

</head>
<body>

<table><tr>
 <td align="center">
  Counter<br>yes / no<br>
  <input id="ytot" type="text" value="" size="4" readonly="readonly">
  <input id="ntot" type="text" value="" size="4" readonly="readonly">
 </td>
 </tr><tr>
 <td align="center">
  <br><br>
  <input type="button" value="yes" OnClick="add_yes()">
  <input type="button" value="no" OnClick="add_no()">
 </td></tr>
 </table>

</body>
</html>

Now, You may still shape both the text-fields and the buttons, by adding as an Attribute:
Code:
style="background-color: ; color: ; font-family: ; font-size: ; font-weight: ; text-align: ;"

With border: ; or border: 1px solid black; as well.

Kind of issue, IExplorer wants a gap of time between two consecutive hits, to react. So, User very quickly submitting two "yes" (likewise a double-clicking), will get one only on the Counter, yet.
Issue still affects both the button way and the link way, to trigger the JS function. This is how, for a link:
Code:
<a href="javascript: add_yes();" style="text-decoration: none;">yes</a><
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> General HTML All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial