By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Incrementing a field

P: n/a
I've got an embedded system that uses a javascript-enabled browser as a
front end.

The input system consists of an encoder which generates + and - chars, and
a couple of keys that generate Tab and Shift-Tab for navigation.

Each field in the form is numerical, and has certain properties; for
example, one field represents %, and has a min of 0, a max of 100, and
increments of 1.

I need to come up with some javascript code that would take take those +
and - chars, and increment/decrement the field values so that the user can
'dial in' the value they need....

I am a complete newbie in the world of Javascript, and I can't figure out
where to begin....

(I've got some other stuff already written, but this aspect of the page is
stumping me....)

I would appreciate any suggestions or references for this....

--Yan
Jan 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Captain Dondo" <ya*@NsOeSiPnAeMr.com> wrote in message
news:pa****************************@NsOeSiPnAeMr.c om...
I've got an embedded system that uses a javascript-enabled browser as a
front end.

The input system consists of an encoder which generates + and - chars, and
a couple of keys that generate Tab and Shift-Tab for navigation.

Each field in the form is numerical, and has certain properties; for
example, one field represents %, and has a min of 0, a max of 100, and
increments of 1.

I need to come up with some javascript code that would take take those +
and - chars, and increment/decrement the field values so that the user can
'dial in' the value they need....

I am a complete newbie in the world of Javascript, and I can't figure out
where to begin....

(I've got some other stuff already written, but this aspect of the page is
stumping me....)

I would appreciate any suggestions or references for this....

--Yan


If the following doesn't help (watch for word-wrap),
could you post a stripped down version of your code?

<html>
<head>
<title>plusminus.htm</title>
<script type="text/javascript">
function plusminus(num,boo) {
var val = document.getElementById("num"+num).value;
(boo) ? val++ : val--;
document.getElementById("num"+num).value = val;
}
</script>
</head>
<body>
<form action="" method="get">
<input type="text" id="num1" size="3" maxlength="3" value="0">
<input type="button" value="+" onclick="plusminus(1,true)">
<input type="button" value="-" onclick="plusminus(1,false)">
<br>
<input type="text" id="num2" size="3" maxlength="3" value="0">
<input type="button" value="+" onclick="plusminus(2,true)">
<input type="button" value="-" onclick="plusminus(2,false)">
</form>
</body>
</html>
Jan 17 '06 #2

P: n/a
On Tue, 17 Jan 2006 08:33:00 -0600, McKirahan wrote:

<html>
<head>
<title>plusminus.htm</title>
<script type="text/javascript">
function plusminus(num,boo) {
var val = document.getElementById("num"+num).value;
(boo) ? val++ : val--;
document.getElementById("num"+num).value = val;
}
</script>
</head>
<body>
<form action="" method="get">
<input type="text" id="num1" size="3" maxlength="3" value="0">
<input type="button" value="+" onclick="plusminus(1,true)">
<input type="button" value="-" onclick="plusminus(1,false)">
<br>
<input type="text" id="num2" size="3" maxlength="3" value="0">
<input type="button" value="+" onclick="plusminus(2,true)">
<input type="button" value="-" onclick="plusminus(2,false)">
</form>
</body>
</html>


I think your code uses buttons to increment and decrement.... That won't
work; I don't have a mouse. All I have is a tab key, a shift-tab key, and
a + and - key....

So what I'm trying to do is figure out some way to tab to field 'num1',
then when a '+' is entered into it, either erase it and or convert it
somehow into an increment....

I've even thought about some sort of hidden text field that would be
active and serve as input for the +- chars, and then a display only field
for the numerical value...

I can post code later today but it ain't much.... I haven't even figured
out an approach for this...

--Yan
Jan 17 '06 #3

P: n/a
"Captain Dondo" <ya*@NsOeSiPnAeMr.com> wrote in message
news:pa***************************@NsOeSiPnAeMr.co m...
On Tue, 17 Jan 2006 08:33:00 -0600, McKirahan wrote:
[snip]
I think your code uses buttons to increment and decrement.... That won't
work; I don't have a mouse. All I have is a tab key, a shift-tab key, and
a + and - key....

So what I'm trying to do is figure out some way to tab to field 'num1',
then when a '+' is entered into it, either erase it and or convert it
somehow into an increment....

I've even thought about some sort of hidden text field that would be
active and serve as input for the +- chars, and then a display only field
for the numerical value...

I can post code later today but it ain't much.... I haven't even figured
out an approach for this...

--Yan


Try this. Watch for word-wrap.

<html>
<head>
<title>plus_minus.htm</title>
<script type="text/javascript">
function plus_minus(num,e) {
// if not Netscape, get IE event
if ( !e ) e = window.event;
if ( !e ) return true;
// Get valid ascii character code
var key = typeof e.keyCode != 'undefined' ? e.keyCode : e.charCode;
// process only the "+" and "-" keys
var val = document.getElementById("Num"+num).value;
if (key == 43) val++;
if (key == 45) val--;
document.getElementById("Num"+num).value = val;
document.getElementById("Num"+num).select();
// cancel the default submit
if (e.preventDefault) {
e.preventDefault();
} else {
window.event.returnValue = false;
}
}
function window.onload() {
document.getElementById("Num1").focus();
document.getElementById("Num1").select();
alert("Press the '+' or '-' key in a field...");
}
</script>
</head>
<body>
<form>
<input type="text" id="Num1" size="3" maxlength="3" value="0"
style="text-align:center" onkeypress="return plus_minus(1)">
<input type="text" id="Num2" size="3" maxlength="3" value="0"
style="text-align:center" onkeypress="return plus_minus(2)">
<input type="text" id="Num3" size="3" maxlength="3" value="0"
style="text-align:center" onkeypress="return plus_minus(3)">
</form>
</body>
</html>

The only keys that will work are:
Tab, Shift+Tab, Plus, and Minus.
Jan 17 '06 #4

P: n/a
McKirahan wrote:
Try this. Watch for word-wrap.
<snip>
The only keys that will work are:
Tab, Shift+Tab, Plus, and Minus.


Thanks. I'm trying to get it to work; I'll post back w/ code once I'm
done.... (It's a learning thing for me....)

--Yan
Jan 17 '06 #5

P: n/a
JRS: In article <pa***************************@NsOeSiPnAeMr.com> , dated
Tue, 17 Jan 2006 07:08:32 remote, seen in news:comp.lang.javascript,
Captain Dondo <ya*@NsOeSiPnAeMr.com> posted :

I think your code uses buttons to increment and decrement.... That won't
work; I don't have a mouse. All I have is a tab key, a shift-tab key, and
a + and - key....


In a well-designed application, it should be possible to do anything
without a mouse (except pointing at locations of pictures).

Consider those using a laptop in a train speeding over bumpy track !

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jan 18 '06 #6

P: n/a
On Wed, 18 Jan 2006 13:57:10 +0000, Dr John Stockton wrote:

In a well-designed application, it should be possible to do anything
without a mouse (except pointing at locations of pictures).

Consider those using a laptop in a train speeding over bumpy track !


Well, I have 12 function keys, up-down-left-right keys, a
pick/select/enter (whatever you want to call it) key, and a + and a - key.
The 12 function keys are 'bookmarks' or 'shortcuts'; they take you
directly to a web page.

With that, I have to do browser navigation and fill a form with numerical
data.

An interesting problem, especially for someone who doesn't speak
javascript very well...
Jan 19 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.