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

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

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <c1**************************@posting.google.com >, david@scene-
double.co.uk enlightened us with...
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

Jul 23 '05 #2

P: n/a
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.
Jul 23 '05 #3

P: n/a
kaeli <ti******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <c1**************************@posting.google.com >, david@scene-
double.co.uk enlightened us with...
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.

--


<!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>
Jul 23 '05 #4

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.