PDA

View Full Version : increase value by 1 with textbox


petertran123
06-24-2003, 04:27 PM
Hello all,

i pulled out 10 records with textboxes for each, but they have the same field name. How do i automatically looping through each field?. When i first enter number 100 to first textbox and tab to second textbox i want it auto fill in 101 for second textbox and so on. Can someone help me please. Thanks


this is an example: i have number 100 in my database, when i first call recordset the first field of texbox automatically fill in 100, and when i tab to the next box i want auto enter 101...so on. Does it make sence to you? i'm sorry i can't explain well

textbox(1) = 100
textbox(2) = 101
textbox(3) = 102
textbox(4) = 103
...... so on

raf
06-24-2003, 07:39 PM
Do you want to have these values filled in on screen, in the form? The you need some javascript. Or do you want the values generaed serversided and processed, without showing them inside textboxes?

david7777
06-25-2003, 09:28 AM
Seems like javascript is needed... From what i understand anyway...

petertran123
06-25-2003, 01:19 PM
i want to be able to show on the form. Do you have any client site script to do the work? thanks for yours reply

petertran123
06-25-2003, 03:27 PM
Raf can you help me how to write a code to generate in server site according to my first question. Thanks for you help

raf
06-25-2003, 04:12 PM
Raf can you help me how to write a code to generate in server site according to my first question.µ

Sure. Something like

response.write("<form name=""Create table"" action=""insert.asp"" method=""post"">)
dim i
i=100
do while rsrecordsetname.EOF=False
response.write("<br /><input type=""text"" name=""varname"" size=""20"" value=""" & i & """>")
i=i+1
rsrecordsetname.MoveNext
loop
response.write("<br /><br /><input type=""submit"" value=""Submit"" name=""Insert"">")
response.write("</form>")

rsrecordsetname should be replaced by your recordsetsname
So for each record there will be a textbow (with the same name) and the values will be 100, 101, 102, ... The client can change these values then.
If you wan't to insert values from your db, you could use something like

response.write("<form name=""Create table"" action=""insert.asp"" method=""post"">)

do while rsrecordsetname.EOF=False
response.write("<br /><input type=""text"" name=""varname"" size=""20"" value=""" & rsrecordsetname.Fields("variabelname") & """>")
rsrecordsetname.MoveNext
loop
response.write("<br /><br /><input type=""submit"" value=""Submit"" name=""Insert"">")
response.write("</form>")

rsrecordsetname and variabelname should be replaced by your recordsetsname and variabelname (where the values are stored in) from your db

Or isn't this what you're looking for?

whammy
06-26-2003, 12:29 AM
My famous question... what are you trying to accomplish?

And by that, I don't mean in code... I mean in English. Surely this can't be the simplest way? It doesn't seem like what you want should be in updatable fields in a form... but I could be wrong.

:confused:

whammy
06-26-2003, 12:31 AM
Oh wait... I think I understand you. But I think in order to help you out correctly I'd need to see an example of your code to help explain. :|

You might want to set the initial value of each textbox to part of an array from the data you retrieved from the recordset. Instead of filling it in when the user tabs, just set that to the "defaultValue" - or only set that value onclick, onfocus, or onchange (depending upon what you're trying to do, which is a bit sketchy here!).

petertran123
06-26-2003, 04:01 PM
Thanks for your kind reply

to make thing simple, i re-question of how to increase by 1.

i have one field name can display up to 20 rows of record within the textboxes. (note: there are the same name for all 20 textboxes)

textbox(i)
textbox(i)
textbox(i)
....

Now, i want to pull out a record from SQL database. My first Record will show "1234567". I want this number automatically show on to first row, and then next row will increase by 1

textbox(i): 1234567
textbox(i): 1234568
textbox(i): 1234569

can someone help me how to solve this problem. I'm truly appreciate it. Thanks.

whammy
06-26-2003, 04:04 PM
Hmm, can't you just use while not rs.EOF? like:

Do While NOT rs.EOF

Response.Write("<input type=""text"" name=""yourname"" value=""" & rs("yourfieldname") & """ />

rs.MoveNext
Loop

?

Or do you need to only get one record, and then increment from there?

petertran123
06-26-2003, 05:42 PM
yes i do want to get one record, and then increment from there.

i write this code to increase value by 1, but it just increase 1 and display all value the same. :confused:




Dim i, strBegCkNo2
For i = 1 to Request("CheckAll").Count

strBegCkNo1 = Request.Form("BegCkNo1")(i)
strBegCkNo2 = strBegCkNo1 + 1

SET rsData2 = conn2.Execute(strSQL2)
Next

whammy
06-26-2003, 06:36 PM
Have you tried doing it in javascript? Perhaps something like:

var initialValue = <% = "12345" %>;
var txtbox = document.forms[0].checkboxName;
for (var i = 0; i < txtbox.length; i ++)
{
txtbox[i].value = initialValue;
initialValue ++;
}


Not tested, but you probably see what I mean...

petertran123
06-26-2003, 07:41 PM
thanks Whammy

It works.. 5 stars for you

:thumbsup:

whammy
06-26-2003, 08:14 PM
Cool! :)