Copy info from 1 text box to another.....

D

David

Hi,

I hope this is the correct place for this post.

I have an asp page with a form.
The form has 2 text boxes for entering a serial number range.
first serial & last serial

In a variable on the asp page I have a quantity.
What I want is that when the user enters a serial number in the first
text box and presses the tab key to set focus to the second text box,
I want the second box to copy the first, but to increase by the qty in
my variable

i.e. Text Box 1:
User types: 1104555666 and presses tab

Qty in variable is 10

1104555666 should increase by 10 but include the first, i.e. -1 on the
end.

Text box 2 should then display 1104555675


How is this possible ?

Appreciate your help


David
 
K

kaeli

david@scene- said:
In a variable on the asp page I have a quantity.
What I want is that when the user enters a serial number in the first
text box and presses the tab key to set focus to the second text box,
I want the second box to copy the first, but to increase by the qty in
my variable

Okay, ASP runs on the server. Javascript runs on the client. So, the
important question is whether you expect that ASP variable to change based on
what the client entered. If so, use postback and do this with ASP.
If not, it's just mostly normal javascript with one little piece generated by
ASP.
i.e. Text Box 1:
User types: 1104555666 and presses tab

Qty in variable is 10

Okay, the variable is only 10 when the doc is still on the server. I'll call
the variable myVariable for both server-side and client-side and assume it is
NOT a string (i.e. is integer, float, etc)...
<script type="text/javascript">
var myVariable = <%= myVariable %>;
</script>

Now you can access the variable through myVariable on the client. You can
change the value of the javascript variable as needed.

But, as I said, if you expect the ASP var to change, sorry, it can't be done
on the client. The server has already finished with it.
Using postback sends form data back to the server for another round of
processing without wiping out the form values. I believe it is only available
in .NET, not ASP classic.

--
--
~kaeli~
"When dogma enters the brain, all intellectual activity ceases"
-- Robert Anton Wilson
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
R

RobG

David wrote:
[...]
How is this possible ?

Client JS should be something like:

<script type="text/javascript">
// I've made theRange as a global, but could be
// local inside the function
var theRange = 10;

function doCalc(x,y){
y.value = 1*x.value + 1*theRange - 1;
}
</script>
<form action="">
<input type="text" width="100px" name="in1" id="in1"
onblur="doCalc(this,this.form.qty)">
<input type="text" width="20px" name="qty" id="qty">
</form>

Just set the value of "theRange" from the server, or allow the user to
modify it in the page.

Rob.
 
R

RobB

kaeli said:
Okay, ASP runs on the server. Javascript runs on the client. So, the
important question is whether you expect that ASP variable to change based on
what the client entered. If so, use postback and do this with ASP.
If not, it's just mostly normal javascript with one little piece generated by
ASP.


Okay, the variable is only 10 when the doc is still on the server. I'll call
the variable myVariable for both server-side and client-side and assume it is
NOT a string (i.e. is integer, float, etc)...
<script type="text/javascript">
var myVariable = <%= myVariable %>;
</script>

Now you can access the variable through myVariable on the client. You can
change the value of the javascript variable as needed.

But, as I said, if you expect the ASP var to change, sorry, it can't be done
on the client. The server has already finished with it.
Using postback sends form data back to the server for another round of
processing without wiping out the form values. I believe it is only available
in .NET, not ASP classic.

--

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript">

/*
* asp: var qty = <%= qty %>;
*/

var qty = 10; //output

function fieldchk(obj)
{
var v = obj.value;
if (/\D/g.test(v))
{
alert('The first serial number must consist of digits only.');
obj.value = '';
setTimeout(function(){obj.focus();}, 50);
return;
}
else obj.form.elements.lastserial.value = v - 1 + qty;
}

</script>
</head>
<body>
<form style="width:220px;">
first serial number » <input type="text" name="firstserial" value=""
size="10" onchange="fieldchk(this)" />
last serial number » <input type="text" name="lastserial" value=""
size="10" readonly="readonly" style="border:none;" />
</form>
</body>
</html>
 
D

David Gordon

Thanks Rob,

Works brilliantly !!

I have only one issue.
Sometimes my users need to enter a 0 (Zero) in text box 1 if there are
no serial numbers for this particular item.

If the user enters a 0, how can I adapt the code to copy only a 0 to
textbox 2 if a 0 is entered in text box 1.

Otherwise the function should work as you wrote.

Appreciate your thoughts.


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top