Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

increase increment 5

Status
Not open for further replies.

iLy54

Programmer
Sep 5, 2002
33
0
0
ZA
Hi people.
i've reached a dead end with this one. i want for this to happen:
every time a link is pressed a number in a text area should increase by 1.sumthing like this:
5 Add
add would be the link. so everytime u click on add the number in the textarea here being 5 would increase by 1.
So if i was to click add it would show 6 and then 7 and so on.
does anyone know of a solution to my challenge?
any help would be appreciated.
thanx -Mon3y is the r00t of all evil and every man needs roots-
 
<html>
<head>
<title>Untitled</title>
<script>
function addIt(){
theValue=parseInt(txt.value);
theValue++;
txt.value=theValue;
}
</script>
</head>

<body>

<input type=&quot;text&quot; id=&quot;txt&quot; value=5><a href=&quot;javascript:addIt()&quot;>Add</a>

</body>
</html>
 
Code:
<Script language=&quot;jscript&quot;>
function increase() {
  var inpt = document.getElementById(&quot;counter&quot;);
  inpt.value = inpt.value + 1;
}
</script>
<input id=&quot;counter&quot; value=&quot;0&quot;>
<a href=&quot;#&quot; onclick=&quot;increase();&quot;>add</a>
Water is not bad as long as it stays out human body ;-)
 
thanx guys. you were both very helpful.
u both deserve stars. -Mon3y is the r00t of all evil and every man needs roots-
 
i got this script wrkin fine.so hw would i use gifs as the numbers, if i have 0.gif to 9.gif.
so the script will still do the same function but use gifs instead.
like when u press add and the value is 9,it will use both 1.gif and 0.gif to make 10.
if this is posible can anyone direct me please. -Mon3y is the r00t of all evil and every man needs roots-
 
How many digits is it likely to get to? Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
it would reach a maximum of 5 digits. -Mon3y is the r00t of all evil and every man needs roots-
 
HERE YOU GO:

<!--assume images named 0.gif-9.gif-->

<script language=&quot;javascript&quot;>
var numberClicks = &quot;-1&quot;;
function addClick(){
var tempNumber = parseInt(numberClicks);
var htmlString = &quot;&quot;;
tempNumber++;
numberClicks = &quot;&quot; + tempNumber;
var i;
for(i=0; i<numberClicks.length; i++){
htmlString += &quot;<img src='&quot; + numberClicks.charAt(i) + &quot;.gif'>&quot;
}
numberImages.innerHTML = htmlString;
}

</script>


<a id=&quot;numberImages&quot;></a><a href=&quot;javascript:addClick()&quot;>Add</a>

<script language=&quot;javascript&quot;>
addClick();
</script>
 
Cheyney, your script works like a dream. exactly what i needed, but there is sumthing that i would like to happen.

at the moment everytime i close the browser and then the number refreshes back to 0. i dont want that to happen. what i want is that whateva the number is at, say 17 it should set that as the default number. so when i start a new session 17 would be the number i see.
is this possible cos i'v noticedeven with the other scripts it does the same. -Mon3y is the r00t of all evil and every man needs roots-
 
you can use cookies to keep track of the count on a computer. There are plenty of how-to's on the web regarding cookies.

cookies will keep the count distinct to the client computer (if they're enabled on that computer). If you want to keep a count distinct to the whole application (like a page counter, where a visitor sees the sum of everyones clicks), you need to use some server side option, like asp or jsp.

cheyney
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top