SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    pblm in validating multiple text box having same name

    Hi All,
    I have a problem in validating the text field having same name.
    i am having the following code snippet.



    <script>
    function multipleobjectvalidation(objectname,type,index)
    {
    if(objectname.length!=null)
    {
    var len=objectname.length;
    for(var i=0;i<len;i++)
    {
    if(type=='i')
    {
    //calling for single text box
    validateinteger(objectname[i]);
    return;
    }
    }
    }

    }

    //this code works fine
    function validateinteger(thisForm)
    {
    for (i = 0; i < thisForm.value.length; i++)
    {
    if(!(isDigit(thisForm.value.charAt(i))))
    {
    alert("Invalid number");
    thisForm.focus();
    break;
    }
    }
    }

    //this code works fine
    function isDigit (c)
    { return ((c >= "0") && (c <= "9"))
    }


    </script>



    <html>
    <%for(int i=0;i<4;i++)
    {%>
    <td><input type="text" name="timerequired" onBlur="multipleobjectvalidation(this.form.timerequired,'i','<%=i%>')"></td>

    <%}%>

    </html>



    The above code works fine in the case of single text box(i checked it).When i try to apply the above code for the mutilple text box it provides alert message two times.I called this function in onblur condition.So when u click on other text box(having the same name)it tries to validate again and displays alert message two times.In other cases it works fine.Can anyone tell me the problem.


    Thanks
    maruthi

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why this?
    Code:
    <input......onBlur="multipleobjectvalidation(this.form.timerequired,'i','<%=i%>')">
    That will pass an array reference, if there are two or more elements with that name. You could pass just the specific object, using this; but it's unclear what the game plan is here.....more details?
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to make sure whick text box index is clicked by the user.So that we can directly call the object specific element instead of checking the array.
    Anyhow its just for a try?There's no pblm in that one.

    But can u able to identify my pblm?


Bookmarks

Posting Permissions

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