• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript Problem

jongyoo

Member
I've got this code where when you click the '-' or '+' link the text in the textbox increments or decrements. But let's say this is at the end of the page after it is scrolled all the way to the bottom; when I click it, the page zooms back up and it's annoying because I have to scroll down again to click it.

The reason why there are so many breaks is to make it be at the bottom where you have to scroll to access it. Put the code below in the notepad as HTML and view it. When you click the java link, it will zoom back up. Is there anyway I can prevent that? I know how to code but little stuff like this, does me in. Thanks

-jong

<html>
<head>

<script type="text/javascript">
function increment(test){

if (test.value.charCodeAt(0) < 90){
if(test.value.charCodeAt(0) == 45){test.value = String.fromCharcode(eval(45))}
test.value = String.fromCharCode(eval(test.value.charCodeAt(0) + 1))
}else
test.value = String.fromCharcode(eval(90))
}

function decrement(test){
if (65 < test.value.charCodeAt(0)){
test.value = String.fromCharCode(eval(test.value.charCodeAt(0) - 1))
}else
test.value = String.fromCharcode(eval(65))
}
</script>



</head>
<body>
<form>
Enter random text
<br>
<br>

<br>
<br>

<br>
<br>

<br>
<br>

<br>
<br>

<br>
<br>

<br>
<br>
<br>
<br>

<br>
<br>

<A href="#" onclick="javascript😀ecrement(num)">-</a>
<input type="text" name="test" value="A" id="num" size="1">
<A href="#" onclick="javascript:increment(num)">+</a>

</form>

</body>
</html>
 
Try this for your increment function

function increment() {
document.form[0].test.value = document.form[0].value +1;
}


To answer your question, it's because you are using a hyperlink for the buttons. You would be better off using
<input type=button onclick="increment();" value="+">
<input type=button onclick="decrement();" value="-"> and then use the above functions.

You can replace form[0] with the name of the form, if you give your form a name 🙂
and for decrement just change the + to a minus
 
Back
Top