setting tabindex

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    setting tabindex

    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="chkqt y(this.name);" tabindex="<?=$i ?>">[/HTML]

    [CODE=javascript]
    function chkqty(nm){
    k=nm.indexOf('[');
    p=nm.indexOf(']');
    k=k+1;
    v=nm.substr(k,p-k);
    v=parseInt(v,10 );
    box=document.ge tElementById("q ty["+v+"]").value;
    if(parseFloat(b ox)== 0 || box.length==0) {
    //just alert
    alert("Error: Qty is empty!");
    // document.getEle mentById(nm).fo cus();
    document.getEle mentById("qty["+v+"]").value="" ;
    return false;
    }

    else{
    var checkOK = "0123456789 .";
    var checkStr = document.getEle mentById("qty["+v+"]").value;
    var allValid = true;
    for (i = 0; i < checkStr.length ; i++)
    {
    ch = checkStr.charAt (i);
    for (j = 0; j < checkOK.length; j++)
    if (ch == checkOK.charAt( j))
    break;
    if (j == checkOK.length)
    {
    allValid = false;
    break;
    }
    }
    if (!allValid)
    {
    alert("Please enter only numbers in the \"Qty \" field.");
    document.getEle mentById("qty["+v+"]").focus();
    document.getEle mentById("qty["+v+"]").value="" ;
    return (false);
    }
    else{

    qty=document.ge tElementById("q ty1["+v+"]").value;
    qty1=document.g etElementById(" qty["+v+"]").value
    //alert(recqty);
    //alert(drwqty);
    if(qty>qty1){

    alert(' qty cannot be more then qty1');
    document.getEle mentById("qty["+v+"]").focus();
    document.getEle mentById("qty["+v+"]").value="" ;
    return false;
    }

    }
    }

    }[/CODE]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Originally posted by SSG001
    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.

    Comment

    • SSG001
      New Member
      • Oct 2007
      • 110

      #3
      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.

      [CODE=javascript]
      if(qty>qty1){

      alert(' qty cannot be more then qty1');
      document.getEle mentById("qty["+v+"]").focus();
      //it doesnt remain in this field after alerting the message it goes to the next field
      document.getEle mentById("qty["+v+"]").value="" ;
      return false;
      }[/CODE]

      Thanks

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        • SSG001
          New Member
          • Oct 2007
          • 110

          #5
          It starts with zero

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            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.

            Comment

            • rnd me
              Recognized Expert Contributor
              • Jun 2007
              • 427

              #7
              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.

              Comment

              • SSG001
                New Member
                • Oct 2007
                • 110

                #8
                How do is set the input boxes tabindex dynamically to -1 ?

                Comment

                • rnd me
                  Recognized Expert Contributor
                  • Jun 2007
                  • 427

                  #9
                  Originally posted by SSG001
                  How do is set the input boxes tabindex dynamically to -1 ?

                  elmInput.setAtt ribute("tabinde x", -1);

                  Comment

                  Working...