SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: alert problem

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2002
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    alert problem

    hi how are you doing? I would like to know how to alert when a user doesn't put his name less than 4 ch.

    In other words when a user registers my username, it should be more than 4 characters. Then if a user puts less than 4ch, it will come out alert.

    Could you tell me how to do it with my script ?

    What I did was if a user doesn't put anything, alert will come out.


    PHP Code:
     function chk(f){
     
     
       if(
    f.fname.value=='' && f.fname.value<=){
       
    alert('Please input your first name')
       return 
    false
       
    }
       
       
       
       else  {
       
       return 
    true
       
       
    }
       
       } 

  2. #2
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be:

    Code:
    function chk( f )
    {
        if( f.fname.value == '' && f.name.value.length <= 4 )
        {
            alert( 'Please input your first name' );
            return false;
        }
        else
        {
            return true;
        }
    }
    There, even though I don't know much JS, I believe that works ;P
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If f.fname.value == '' is true, then f.name.value.length <= 4 is true too, so you could write it
    if( f.name.value.length <= 4 ) ...

  4. #4
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, im not a javascript guy, so back to PHP for me ;P
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2002
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did both ways,but now working at all
    Me again I would like to know how to alert when a user doesn't put his fullname,username,password,nickname less than 4 chracters.
    Should I use else if. Acutally, I used it but not working now.

    Do you have any idea to solove this problem.

    4 conditons(fullname,username,password,nickname)

    please hlep.

    In other words when a user registers his fullname, username, password,nickname, it should be more than 4 characters. Then if a user puts less than 4ch, it will come out alert.




    Could you tell me how to do it with my script ?

    What I did was if a user doesn't put anything, alert will come out.






    PHP Code:

    <script language="javascript"
    <!-- 



    function 
    chk(f){ 


       if(
    f.fname.value=='  '){ 
       
    alert('Please input your first name'
       return 
    false 
       

        
        
        
       else  { 
        
       return 
    true 
        
       

        
       } 
    //--> 
    </script> 

  6. #6
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
      <head>
        <script type="text/javascript">
          function check(frm) 
          {
            var error = "";
            if(frm.txt1.value.length <= 4) error += "Text 1 <= 4 ch\n";
            if(frm.txt2.value.length <= 4) error += "Text 2 <= 4 ch\n";
            if(frm.txt3.value.length <= 4) error += "Text 3 <= 4 ch\n";
            if(error.length == 0) 
            {
              return true; 
            }
            else
            {
              alert(error); 
              return false;
            }
          }
        </script>
      </head>
      <body>
        <form>
          Text 1: <input type="text" name="txt1"><br>
          Text 2: <input type="text" name="txt2"><br>
          Text 3: <input type="text" name="txt3"><br>
          <input type="submit" onclick="return check(this.form)">
        </form>
      </body>
    </html>


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
  •