Results 1 to 6 of 6

Thread: required field array

  1. #1
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default required field array

    I have an input field
    Code:
    <form method="post" name="frmname">
    <input type="text" name="txtcost[]" />
    <input type="submit"  name="btnsubmit">
    </form>
    when the user leave the field blank, it will display an alert "Please enter'
    could you please help me?

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Code:
    <form method="post" name="frmname" onsubmit="var result; if((result=!this['txtcost[]'].value.match(/\S/))){alert('Please Enter');}return result;">
    <input type="text" name="txtcost[]" />
    <input type="submit"  name="btnsubmit">
    </form>

  3. #3
    Join Date
    Aug 2008
    Posts
    23
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by clueful View Post
    Code:
    <form method="post" name="frmname" onsubmit="var result; if((result=!this['txtcost[]'].value.match(/\S/))){alert('Please Enter');}return result;">
    <input type="text" name="txtcost[]" />
    <input type="submit"  name="btnsubmit">
    </form>
    not working, please help..

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    You shouldn't use "[]" in the names of form elements. Just use clear, descriptive names.
    - Mike

  5. #5
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Quote Originally Posted by abs0lut View Post
    not working, please help..
    It does work.
    I hope you meant the alert to appear when the button is pressed, because alerting on blur isn't clever.

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    <form method="post" name="frmname">
    <input type="text" name="txtcost[]" value="[Enter a value]" onkeyup="if (this.value == '') this.value = '[Enter a value]';" onfocus="this.value = '';" />
    <input type="submit" name="btnsubmit">
    </form>
    Is that what you want?
    - Mike

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
  •