473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

setting tabindex

110 100+
I have follwing function to check if the user enters blank non zero value and other then numbers in the text box
// this is in the for loop but tabindex goes ahead and fires the event again how do i prevent the tabindex going to the next textbox
[HTML]<input type="text" name="<?='qty['.$i.']'?> id="<?='qty['.$i.']'?>" onchange="chkqty(this.name);" tabindex="<?=$i?>">[/HTML]

Expand|Select|Wrap|Line Numbers
  1. function chkqty(nm){
  2. k=nm.indexOf('[');
  3. p=nm.indexOf(']');
  4. k=k+1;
  5. v=nm.substr(k,p-k);
  6. v=parseInt(v,10);
  7. box=document.getElementById("qty["+v+"]").value;
  8.  if(parseFloat(box)== 0 || box.length==0) {
  9.  //just alert 
  10.           alert("Error: Qty is empty!");
  11.         // document.getElementById(nm).focus();
  12.            document.getElementById("qty["+v+"]").value="";
  13.              return false;
  14.   }
  15.  
  16.   else{
  17.            var checkOK = "0123456789.";
  18.             var checkStr = document.getElementById("qty["+v+"]").value;
  19.             var allValid = true;
  20.             for (i = 0;  i < checkStr.length;  i++)
  21.             {
  22.             ch = checkStr.charAt(i);
  23.             for (j = 0;  j < checkOK.length;  j++)
  24.             if (ch == checkOK.charAt(j))
  25.             break;
  26.             if (j == checkOK.length)
  27.             {
  28.             allValid = false;
  29.             break;
  30.             }
  31.             }
  32.             if (!allValid)
  33.             {
  34.             alert("Please enter only numbers in the \"Qty \" field.");
  35.             document.getElementById("qty["+v+"]").focus();
  36.             document.getElementById("qty["+v+"]").value="";
  37.             return (false);
  38.             }    
  39.             else{
  40.  
  41.                 qty=document.getElementById("qty1["+v+"]").value;
  42.                 qty1=document.getElementById("qty["+v+"]").value
  43.                 //alert(recqty);
  44.                 //alert(drwqty);
  45.                 if(qty>qty1){
  46.  
  47.                     alert(' qty cannot be more then qty1');
  48.                     document.getElementById("qty["+v+"]").focus();
  49.                     document.getElementById("qty["+v+"]").value="";
  50.                     return false;
  51.                 }
  52.  
  53.             }
  54.     }        
  55.  
  56. }
Mar 4 '08 #1
8 2563
acoder
16,027 Expert Mod 8TB
I have follwing function to check if the user enters blank non zero value and other then numbers in the text box
// this is in the for loop but tabindex goes ahead and fires the event again how do i prevent the tabindex going to the next textbox
What do you mean by tabindex firing the events again? Note that you can use alternatives to alert, e.g. a DHTML div that appears when an error occurs.
Mar 5 '08 #2
SSG001
110 100+
i mean in below code i have mentioned whever the qty is greater then qty1
alert is shown the focus goes to the other text box instead of remaining there it self although i hev given saif .focus to that particular field
it goes to the next same field.

Expand|Select|Wrap|Line Numbers
  1. if(qty>qty1){
  2.  
  3.                     alert(' qty cannot be more then qty1');
  4.                     document.getElementById("qty["+v+"]").focus();
  5. //it doesnt remain in this field after alerting the message it goes to the next field
  6.                     document.getElementById("qty["+v+"]").value="";
  7.                     return false;
  8.                 }
Thanks
Mar 6 '08 #3
acoder
16,027 Expert Mod 8TB
I don't think it's the tabindex to blame.

Does your PHP loop start at 0 or 1?

Another point to note is that IDs should not have brackets - see here.
Mar 6 '08 #4
SSG001
110 100+
It starts with zero
Mar 8 '08 #5
acoder
16,027 Expert Mod 8TB
I don't know if it's a typo, but you haven't closed the name attribute in your input tag. Show the HTML version of these input tags.
Mar 8 '08 #6
rnd me
427 Expert 256MB
i believe it is happening because you are setting the .value after calling .focus


reverse it and try again.

it seems that changing the value whilst triggering an alert fires the onchange event, and advances the tab index.

you could also dynamically allocate the all the input's tabindexes to be -1, in which case it will never receive focus, and then advance focus in your validation functions.
Mar 8 '08 #7
SSG001
110 100+
How do is set the input boxes tabindex dynamically to -1 ?
Mar 10 '08 #8
rnd me
427 Expert 256MB
How do is set the input boxes tabindex dynamically to -1 ?

elmInput.setAttribute("tabindex", -1);
Mar 10 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
0
by: Stuart Norris | last post by:
Dear Group, I am having a problem setting SocketOptionName.SendTimeout on a client TCPIP application using the sockets in .NET. From the on-line help it is possible to set a...
1
by: Rachel Suddeth | last post by:
I have an form where the whole display is a tab control (well, that plus a status bar.) I want to set the focus to the first TextBox on the first TabPage when it loads. I tried to put that into...
3
by: Mike Eaton | last post by:
Hi there, I've got what I hope is a simple problem to solve... Here's the back story: I have a windows form. On the form is a panel containing three textboxes. Also on the form is a text box...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
0
by: Barry Flynn | last post by:
Visual Studio 2005 I have a vague recollection that it is possible to set an option which causes the TabIndex property to be displayed on each control. You could then set the required tabindex...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.