473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Incrementing a field

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
6 2520
"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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robin Tucker | last post by:
Hi, I'm in the process of implementing a multi-user system containing an adjacency list (tree structure). I'm using a TIMESTAMP field on each record in the adjacency list in order to tell when...
8
by: JD via AccessMonster.com | last post by:
I am trying to create a field where the primary key field will produce JDP- 001; where the three letters come from the first name, middle intial and last name of my table. I want to auto increment...
1
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've...
2
by: Tim Vadnais | last post by:
Hi, My boss wants to add some logging functionality to some of our tables on update/delete/insert. I need to log who, when, table_name, field name, original value and new value for each record,...
0
by: icezcube | last post by:
I am not a programmer and a newbie with MS Access. I hope you guys can help me with my problem. I'm creating an IT hardware inventory database for my company. We have a few branches and each...
3
by: Adam Sandler | last post by:
Hello, I'm able to reproduce my problem but I haven't been able to figure out why it is happening. MS does have an article about such behavior in...
1
by: senger.kim | last post by:
Hello World, I'm relatively new to MS Access (2003) and am trying to implement something that I feel should be simple but cannot find a solution. Hoping that you can help me or point me where to...
1
by: asandiego | last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need. I hope someone can lead me to what I should do or just an idea to what can be done. What I'm...
3
by: bkberg05 | last post by:
Hi - I have a field called Sequence on a continuous subform. The Sequence field belongs to a table called Project_Draw. This table has many 'Draw' records for each 'Project' record. So then the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.