SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    If field is blank

    I am using javascript to detect if a field is left blank if (Col1.value == ""){return false}else{return confirm("Are you sure you want to add the following table? \n" + CheckTbl.value);} and if the form is left blank the form doesn't submit, but if I type a space in the field and submit the form it submits. How can I fix this issue?

  2. #2
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply add a || and then detect for a " ".
    I would use the function "trim()" to get rid of any spaces, then detect for a empty box.

    Or both.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But if I use trim and put My Column then wouldn't the trim make it output MyColumn? Is there a way to say if it doesn't contain a-z then return false?

  4. #4
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HighCaliber
    But if I use trim and put My Column then wouldn't the trim make it output MyColumn? Is there a way to say if it doesn't contain a-z then return false?
    The trim() function only removes surrounding whitespace from the string.

    http://www.apriori-it.co.uk/Trim.asp

    Regards,
    Jordan

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help bobber205 and J Windebank.


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
  •