Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Other means to alert("")

Options
  • 07-04-2012 8:00pm
    #1
    Closed Accounts Posts: 2,663 ✭✭✭


    I dont like the Alert pop up giving the User a Error Code..

    i like the writeError(" " ) function, where the error message displays next to the text field. from the bit of code i have given how can i make that happen from the source code below ?
    function formValidator(){
        
        var firstname = document.getElementById('firstname');
        var lastname = document.getElementById('lastname');
    
        
    if(isAlphabet(firstname, "Please enter Your First Name")){
    if(isAlphabet(lastname, "Please enter Your Last Name")){
    
                                return true;
                   }
                   }
    return false;
        
    }
    
    
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus();
            return false;
        }
        return true;
    }
    
    function isAlphabet(elem, helperMsg){
        var alphaExp = /^[a-zA-Z]+$/;
        if(elem.value.match(alphaExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    
    
    
      First Name:
                 <br  />      
                 <input type='text' id='firstname'  placeholder="Enter Your First Name" autocomplete="off" />
      </p>
      <p>
                  Last Name: 
                  <br />
                  <input type='text' id='lastname'  placeholder="Enter Your Last Name"  autocomplete="off"/>
          </p>
                  
    


Comments

  • Registered Users Posts: 8,070 ✭✭✭Placebo


    why dont you use console.log ? and see the error in firebug console [mozilla]


  • Registered Users Posts: 2,781 ✭✭✭amen


    why dont you use console.log ? and see the error in firebug console [mozilla]

    because at a guess he wants to display a nice user friendly message to the user of the site ?


  • Registered Users Posts: 516 ✭✭✭Jayo_M


    To get what you want, if I'm understanding properly, you could just create a DOM element in your error-handling step displaying the error message you want next to the input field.


  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    Jayo_M wrote: »
    To get what you want, if I'm understanding properly, you could just create a DOM element in your error-handling step displaying the error message you want next to the input field.


    Will should i create a div tag next to the fields and then display the error Msg from that ?

    have you got a Site that shows you a Demo ?


  • Registered Users Posts: 516 ✭✭✭Jayo_M


    Yeah, an inline div would work. You could have it created before hand with the visibility set to hidden, and then set it to visible when needed, or you could create the div on the fly when its needed. w3schools probably has some JS DOM manipulation examples you could work from.


  • Advertisement
  • Registered Users Posts: 26,558 ✭✭✭✭Creamy Goodness


    There is nothing more ugly than a JavaScript confirm and go or a alert box. If you have used ryanair you'll know my hatred for them.

    Alerts and confirm and go dialogs only look good on iPhones where the iPhone styles them nicely like a push notification.

    Inline div is the way to go. Or better yet use jquery validator plugin.


  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    There is nothing more ugly than a JavaScript confirm and go or a alert box. If you have used ryanair you'll know my hatred for them.

    Alerts and confirm and go dialogs only look good on iPhones where the iPhone styles them nicely like a push notification.

    Inline div is the way to go. Or better yet use jquery validator plugin.


    have you got a Site that shows you Jquery validator for CCV and Credit Cards


  • Registered Users Posts: 26,558 ✭✭✭✭Creamy Goodness




  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    Sorry i mean as Tutorial of some sort.


  • Registered Users Posts: 516 ✭✭✭Jayo_M




  • Advertisement
  • Closed Accounts Posts: 2,663 ✭✭✭Cork24


    Jayo_M wrote: »


    Thanks for that think I didn't already try that ??


  • Registered Users Posts: 516 ✭✭✭Jayo_M


    Second and fifth links no use to you?


Advertisement