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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy validating an array field

    Hi!
    i have a form which is which has an array field
    php code***********
    while($row = mysql_fetch_object(...){
    $tbl .= '<input name="qty['.$x.']" type="text" size="4" maxlength="4"/>';
    ...
    }


    when i try to do something like this, it doesnt like it
    javascript code ***************
    for(i=0;i<total_rows; i++){
    ...
    frm_name.qty[i].value
    ...
    }

    I would like to validate it on submit to check at least one of then has a value and and that the values entered are numeric...thanks

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Harman
    Hi!
    i have a form which is which has an array field
    php code***********
    while($row = mysql_fetch_object(...){
    $tbl .= '<input name="qty['.$x.']" type="text" size="4" maxlength="4"/>';
    ...
    }


    when i try to do something like this, it doesnt like it
    javascript code ***************
    for(i=0;i<total_rows; i++){
    ...
    frm_name.qty[i].value
    ...
    }

    I would like to validate it on submit to check at least one of then has a value and and that the values entered are numeric...thanks

    Can you post your entire form...?



    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by Harman
    Hi!
    i have a form which is which has an array field
    php code***********
    while($row = mysql_fetch_object(...){
    $tbl .= '<input name="qty['.$x.']" type="text" size="4" maxlength="4"/>';
    ...
    }


    when i try to do something like this, it doesnt like it
    javascript code ***************
    for(i=0;i<total_rows; i++){
    ...
    frm_name.qty[i].value
    ...
    }

    I would like to validate it on submit to check at least one of then has a value and and that the values entered are numeric...thanks
    var val = frm_name.elements['qty['+i+']'].value;
    alert(val);

    Here's more info on bracket notation


  •  

    Posting Permissions

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