Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts

    increase value by 1

    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

    Code:
    <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>
    Last edited by petertran123; 07-16-2003 at 01:49 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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)">
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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?

    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++);
    	}
    }

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    currently, the values increase value by 13 not by 1

    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++);
    	}
    }

  • #10
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem i'm running into having increase value by 13 is because i have the page display.asp as below:

    Code:
    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:

    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?

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    it's hard to debug without seeing the page run. do you have it online?

  • #12
    Regular Coder
    Join Date
    Jul 2002
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


    Code:
    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.

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    can you post the generated html code? just attach it in your post.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •