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

How to make JS change input boxes?!?

P: n/a
Ok, here is my scenario: I need to input numbers using my handheld
IPAQ. I figured out how to create an online numeric keypad for
inputting numbers into an input field, what I need to know is how I
can have JS switch from one input field to another based on me
clicking in the empty box. Here is my code:

########## Start of code ###################
<html>

<head>
<title>${TITLE}</title>
<script>

function inpt(nm)
{
ibox = document.tester.number.value+""+nm
document.tester.number.value = ibox;
}
</script>
</head>

<body>

<form name="tester" method=post>
<input type=text name="number">
<input type=text name="sales">
<input type=text name="budget">
<table border=1 cellpadding=1 cellspacing=1>
<tr vheight=20>
<td><input type=button value=" 1" onClick="inpt(1);"></td>
<td><input type=button value=" 2" onClick="inpt(2)"></td>
<td><input type=button value=" 3" onClick="inpt(3)"></td>
</tr>
<tr>
<td><input type=button value=" 4" onClick="inpt(4)"></td>
<td><input type=button value=" 5" onClick="inpt(5)"></td>
<td><input type=button value=" 6" onClick="inpt(6)"></td>
</tr>
<tr>
<td><input type=button value=" 7" onClick="inpt(7)"></td>
<td><input type=button value=" 8" onClick="inpt(8)"></td>
<td><input type=button value=" 9" onClick="inpt(9)"></td>
</tr>
<tr>
<td><input type=button value=" 0" onClick="inpt(0)"></td>
<td colspan=2><input type=reset value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
########## End of code ###################

The above code by default will only input numbers into the "number"
input field. What I would like to do is tell JS to switch the input
to the "sales" or the "budget" field just by me clicking in the box.
I figure I can use the onFocus attribute and tried a few things but no
avail. Any help appreciated.

TIA,
Cranky
Nov 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Something like this should suite ur needs.
But i have not time to add a couple of if statemnets. So right now u
have to click even to the number box. But this can be fixed by 1-2
lines.

<html>

<head>
<title>${TITLE}</title>
<script>
var name;
function inpt(nm)
{

ibox = document.tester.elements[name].value+""+nm
document.tester.elements[name].value = ibox;

}

function foo(obj){
name=obj.name;

}

</script>
</head>

<body>

<form name="tester" method=post>
<input type=text name="number" onfocus="foo(this)">
<input type=text name="sales" onfocus="foo(this)">
<input type=text name="budget" onfocus="foo(this)">
<table border=1 cellpadding=1 cellspacing=1>
<tr vheight=20>
<td><input type=button value=" 1" onClick="inpt(1);"></td>
<td><input type=button value=" 2" onClick="inpt(2)"></td>
<td><input type=button value=" 3" onClick="inpt(3)"></td>
</tr>
<tr>
<td><input type=button value=" 4" onClick="inpt(4)"></td>
<td><input type=button value=" 5" onClick="inpt(5)"></td>
<td><input type=button value=" 6" onClick="inpt(6)"></td>
</tr>
<tr>
<td><input type=button value=" 7" onClick="inpt(7)"></td>
<td><input type=button value=" 8" onClick="inpt(8)"></td>
<td><input type=button value=" 9" onClick="inpt(9)"></td>
</tr>
<tr>
<td><input type=button value=" 0" onClick="inpt(0)"></td>
<td colspan=2><input type=reset value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
May be a bit later i will modify it.

GL.
Cranky wrote:
Ok, here is my scenario: I need to input numbers using my handheld
IPAQ. I figured out how to create an online numeric keypad for
inputting numbers into an input field, what I need to know is how I
can have JS switch from one input field to another based on me
clicking in the empty box. Here is my code:

########## Start of code ###################
<html>

<head>
<title>${TITLE}</title>
<script>

function inpt(nm)
{
ibox = document.tester.number.value+""+nm
document.tester.number.value = ibox;
}
</script>
</head>

<body>

<form name="tester" method=post>
<input type=text name="number">
<input type=text name="sales">
<input type=text name="budget">
<table border=1 cellpadding=1 cellspacing=1>
<tr vheight=20>
<td><input type=button value=" 1" onClick="inpt(1);"></td>
<td><input type=button value=" 2" onClick="inpt(2)"></td>
<td><input type=button value=" 3" onClick="inpt(3)"></td>
</tr>
<tr>
<td><input type=button value=" 4" onClick="inpt(4)"></td>
<td><input type=button value=" 5" onClick="inpt(5)"></td>
<td><input type=button value=" 6" onClick="inpt(6)"></td>
</tr>
<tr>
<td><input type=button value=" 7" onClick="inpt(7)"></td>
<td><input type=button value=" 8" onClick="inpt(8)"></td>
<td><input type=button value=" 9" onClick="inpt(9)"></td>
</tr>
<tr>
<td><input type=button value=" 0" onClick="inpt(0)"></td>
<td colspan=2><input type=reset value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
########## End of code ###################

The above code by default will only input numbers into the "number"
input field. What I would like to do is tell JS to switch the input
to the "sales" or the "budget" field just by me clicking in the box.
I figure I can use the onFocus attribute and tried a few things but no
avail. Any help appreciated.

TIA,
Cranky
Nov 8 '06 #2

P: n/a
ASM
Cranky a écrit :
Ok, here is my scenario: I need to input numbers using my handheld
IPAQ. I figured out how to create an online numeric keypad for
inputting numbers into an input field, what I need to know is how I
can have JS switch from one input field to another based on me
clicking in the empty box. Here is my code:

########## Start of code ###################
<html>

<head>
<title>${TITLE}</title>
<script>
function inpt(nm)
{
document.tester.number.value += ""+nm;
if(stock)
document.tester[stock].value=document.tester.number.value;
}
stock = false;
</script>
</head>

<body>

<form name="tester" method=post>
<input type=text name="number"
onclick="stock=false;">
<input type=text name="sales"
onclick="stock=this.name;this.value=number.value">
<input type=text name="budget"
onclick="stock=this.name;this.value=number.value">

--
ASM
Nov 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.