...

View Full Version : increase value by 1



petertran123
07-16-2003, 01:46 PM
i used Danne's script but don't know how to change the variable name to match.

when i tab to next textbox or click to next textbox. You can see my code is working fine, but the name is not match.

Everything is running fine if i have a textbox name as follows,
------------------------------------------------------------------------
<INPUT TYPE=TEXT NAME=""BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)"">
----------------------------------------------------------------------------

but,

now i have a difference name, which i do not have an object match to the script below.
--------------------------------------------------------------------
<INPUT TYPE=TEXT NAME=""" & iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)"">
-------------------------------------------------------------------------

I wanted to be able to replace whatever it has a name BegCkNo1Con to & iCount & ".BegCkNo1Con How do i do that?. Thanks



<SCRIPT LANGUAGE=JavaScript>
var decrease=false;

function setDecrement(decr){
decrease=decr;
}

function fillTextboxes(el) {
var val=el.value;
var update=false;
if( isNaN(val) || val.search(/[0-9]/g)==-1 ){
el.value=""; // Clear the textbox
return;
}
for (var i = 0; i < document.forms["ChkForm"].BegCkNo1Con.length; i++) {
if (el==document.forms["ChkForm"].BegCkNo1Con[i]) {
update=true;
var j=0;
while (document.forms["ChkForm"].BegCkNo1Con[i]!=document.forms["ChkForm"].BegCkNo1Con[j]) { // Check only the textboxes before the current
if (document.forms["ChkForm"].BegCkNo1Con[i].value==document.forms["ChkForm"].BegCkNo1Con[j].value) {
alert("Duplicated check numbers are not allowed");
document.forms["ChkForm"].BegCkNo1Con[i].focus();
return;
}

j++;
}
}
if (update) {
document.forms["ChkForm"].BegCkNo1Con[i].value=(decrease ? val--: val++);
}
}
}

</script>

Kor
07-16-2003, 01:52 PM
hm, at a first glance... too many quotes...

ex. why?:

<INPUT TYPE=TEXT NAME=""BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)"">

it will be correct to use just a pair of each

<INPUT TYPE=TEXT NAME="BegCkNo1Con" VALUE="" size="10" maxlength="7" onBlur="fillTextboxes(this)">

petertran123
07-16-2003, 02:08 PM
accoring to what i have now. i want to use

<INPUT TYPE=TEXT NAME=""" & iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)"">


instead of

<INPUT TYPE=TEXT NAME=""BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)"">

do you know to work around on this? thanks

arnyinc
07-16-2003, 02:17 PM
This looks like a response.write statement in ASP code (extra quotes and using the & character). View the source of the document and show the HTML after it has been interpreted.

petertran123
07-16-2003, 02:30 PM
this is what it shows when i view source code in HTML
<TD><INPUT TYPE=TEXT NAME="0.BegCkNo1Con" VALUE="" size="10" maxlength="7" onBlur="fillTextboxes(this)"></TD>
<TD><INPUT TYPE=TEXT NAME="1.BegCkNo1Con" VALUE="" size="10" maxlength="7" onBlur="fillTextboxes(this)"></TD>
<TD><INPUT TYPE=TEXT NAME="2.BegCkNo1Con" VALUE="" size="10" maxlength="7" onBlur="fillTextboxes(this)"></TD>

so on...

iCount is a count number of rows from my asp code.

petertran123
07-16-2003, 09:30 PM
i changed my code around but still can't get it to work. I received an error, it nulls or object expected.


*********this is my textbox's name****************
& "<TD><INPUT TYPE=TEXT NAME="""& iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)""></TD>" & vbCrLf _


**************this is script to increase a value by 1. **********

<SCRIPT LANGUAGE=JavaScript>

var decrease=false;

function setDecrement(decr){
decrease=decr;
}

function fillTextboxes(el) {
var val=el.value;
var update=false;
if( isNaN(val) || val.search(/[0-9]/g)==-1 ){
el.value=""; // Clear the textbox
return;
}

for (var i = 0; i < document.forms["ChkForm"].elements[i + ".BegCkNo1Con"].length; i++) {
if (el==document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][i]) {
update=true;
var j=0;
while (document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][i]!=document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][j]) { // Check only the textboxes before the current
if (document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][i].value==document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][j].value) {
alert("Duplicated check numbers are not allowed");
document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][i].focus();
return;
}

j++;
}
}
if (update) {
document.forms["ChkForm"].elements[i + ".BegCkNo1Con"][i].value=(decrease ? val--: val++);
}
}
}

</script>

glenngv
07-17-2003, 07:31 AM
Danne's code is for array of textboxes. Those textboxes with same name. But your textboxes have different names, so they don't form an array.

I think the code for the for-loop should be like this?



var f = document.forms["ChkForm"];
for (var i = 0; i < f.elements.length; i++) {
if (el==f.elements[i + ".BegCkNo1Con"]) {
update=true;
var j=0;
while (f.elements[i + ".BegCkNo1Con"]!=f.elements[j + ".BegCkNo1Con"]) { // Check only the textboxes before the current
if (f.elements[i + ".BegCkNo1Con"].value==f.elements[j + ".BegCkNo1Con"].value) {
alert("Duplicated check numbers are not allowed");
f.elements[i + ".BegCkNo1Con"].focus();
return;
}
j++;
}
}
if (update) {
f.elements[i + ".BegCkNo1Con"].value=(decrease ? val--: val++);
}
}

petertran123
07-17-2003, 01:20 PM
Thanks Glenn, you are the man. I finallly got it's working, but one small problem is. It not increase value by one

if user select desc/asc the values should look like this:

asc:
123456
123457
123458
123459


desc:
123459
123458
123457
123456
123455

would you please take a look at one more time. Thanks so much

petertran123
07-17-2003, 01:25 PM
currently, the values increase value by 13 :o not by 1 :o



var f = document.forms["ChkForm"];
for (var i = 0; i < f.elements.length; i++) {
if (el==f.elements[i + ".BegCkNo1Con"]) {
update=true;
var j=0;
while (f.elements[i + ".BegCkNo1Con"]!=f.elements[j + ".BegCkNo1Con"]) { // Check only the textboxes before the current
if (f.elements[i + ".BegCkNo1Con"].value==f.elements[j + ".BegCkNo1Con"].value) {
alert("Duplicated check numbers are not allowed");
f.elements[i + ".BegCkNo1Con"].focus();
return;
}
j++;
}
}
if (update) {
f.elements[i + ".BegCkNo1Con"].value=(decrease ? val--: val++);
}
}

petertran123
07-17-2003, 04:00 PM
the problem i'm running into having increase value by 13 is because i have the page display.asp as below:



Dim iCount
iCount = 0
Do While Not rsData.EOF
& "<TD><font face=""arial"">" & vbCrlf _
& "<INPUT TYPE=""CHECKBOX"" NAME="""& iCount & ".chkDisplayList"" VALUE=""" & CInt(rsData("TRANS_ID")) & """ checked>" & vbCrlf _
& "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimaryNameFirst") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimaryNameLast") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimarySSN") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & FormatCurrency(rsData("CheckAmt"),2) & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & nTempDate & "</font></TD>" & vbCrlf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimaryNameFirst"" VALUE=""" & rsData("PrimaryNameFirst") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimaryNameLast"" VALUE=""" & rsData("PrimaryNameLast") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimarySSN"" VALUE=""" & rsData("PrimarySSN") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAmt"" VALUE=""" & rsData("CheckAmt") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckDate"" VALUE=""" & nTempDate & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum1"" VALUE=""" & rsData("CheckAuthNum1") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum2"" VALUE=""" & rsData("CheckAuthNum2") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum3"" VALUE=""" & rsData("CheckAuthNum3") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum4"" VALUE=""" & rsData("CheckAuthNum4") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckType"" VALUE=""" & rsData("CheckType") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PaymentID"" VALUE=""" & rsData("PaymentID") & """>" & vbCrLf _



& "<TD><INPUT TYPE=TEXT NAME="""& iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)""></TD>" & vbCrLf _

& "</TD></TR>" & vbCrLf _
'Move to the next record...

rsData.MoveNext
iCount = iCount + 1

'Increment the count variable

Loop




when i enter value in textbox using this code:



var f = document.forms["ChkForm"];
for (var i = 0; i < f.elements.length; i++) {
if (el==f.elements[i + ".BegCkNo1Con"]) {
update=true;
var j=0;
while (f.elements[i + ".BegCkNo1Con"]!=f.elements[j + ".BegCkNo1Con"]) { // Check only the textboxes before the current
if (f.elements[i + ".BegCkNo1Con"].value==f.elements[j + ".BegCkNo1Con"].value) {
alert("Duplicated check numbers are not allowed");
f.elements[i + ".BegCkNo1Con"].focus();
return;
}
j++;
}
}
if (update) {
f.elements[i + ".BegCkNo1Con"].value=(decrease ? val--: val++);
}
}


and i'm ended up to increase value by 13..and is messing up to other fields. would you please tell me what is going on?

glenngv
07-18-2003, 02:56 AM
it's hard to debug without seeing the page run. do you have it online?

petertran123
07-18-2003, 03:32 PM
i'm using intranet, sorry Glenn

i think the reason is increasing the values by 13 because it counts all of the name of iCount in the form. i noticed there are 13 inputs for iCount, (you can see in previous post). Maybe that is a problem. When i enter the number in textbox for increasing:

& "<TD><INPUT TYPE=TEXT NAME="""& iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)""></TD>" & vbCrLf _



for an example: there are 5 rows displaying like this:

the number increase in BegCkNo1con (textbox)

123456 ---> row1
123469 --->row2
123472 ---->row3
123485 ---->row4
123498 ---->row5




Dim iCount
iCount = 0
Do While Not rsData.EOF
& "<TD><font face=""arial"">" & vbCrlf _
& "<INPUT TYPE=""CHECKBOX"" NAME="""& iCount & ".chkDisplayList"" VALUE=""" & CInt(rsData("TRANS_ID")) & """ checked>" & vbCrlf _
& "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimaryNameFirst") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimaryNameLast") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & rsData("PrimarySSN") & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & FormatCurrency(rsData("CheckAmt"),2) & "</font></TD>" & vbCrlf _
& "<TD><font face=""arial"" size=""2"" color=""white"">" & nTempDate & "</font></TD>" & vbCrlf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimaryNameFirst"" VALUE=""" & rsData("PrimaryNameFirst") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimaryNameLast"" VALUE=""" & rsData("PrimaryNameLast") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PrimarySSN"" VALUE=""" & rsData("PrimarySSN") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAmt"" VALUE=""" & rsData("CheckAmt") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckDate"" VALUE=""" & nTempDate & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum1"" VALUE=""" & rsData("CheckAuthNum1") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum2"" VALUE=""" & rsData("CheckAuthNum2") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum3"" VALUE=""" & rsData("CheckAuthNum3") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckAuthNum4"" VALUE=""" & rsData("CheckAuthNum4") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".CheckType"" VALUE=""" & rsData("CheckType") & """>" & vbCrLf _
& "<INPUT TYPE=HIDDEN NAME="""& iCount & ".PaymentID"" VALUE=""" & rsData("PaymentID") & """>" & vbCrLf _



& "<TD><INPUT TYPE=TEXT NAME="""& iCount & ".BegCkNo1Con"" VALUE="""" size=""10"" maxlength=""7"" onBlur=""fillTextboxes(this)""></TD>" & vbCrLf _

& "</TD></TR>" & vbCrLf _
'Move to the next record...

rsData.MoveNext
iCount = iCount + 1

'Increment the count variable

Loop


i looked at the value in check field, i see there are a number follows after the row1 and the number is 123457, then i think there are 13 inputs for "" iCount"" is messing up the whole issue.

glenngv
07-21-2003, 02:57 AM
can you post the generated html code? just attach it in your post.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum