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 5 of 5

Thread: How to

  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    29
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How to

    I'm using an alert to inform the user when value is 0.

    Is there any other way of doing this. Someone here in the forum said that it's obsolute.

    Code:
    ussd = function() {
    			var number_id = escape(document.getElementById('number_id').value);
    			if(number_id == "") {
    				alert('Type a valid mobile number!');
    				return false;
    			}

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    In the HTML

    Code:
    <p id="message"></p>
    Then in the JavaScript you can use the following to insert a message into that paragraph in the HTML

    Code:
    document.getElementById('message').innerHTML = 'Type a valid mobile number!';
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Or you can google for javascript custom dialog box. Or better, search for javascript validation as there are a lot of better ways of informing users of input errors other than displaying a dialog box.
    Last edited by glenngv; 03-26-2014 at 10:06 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    A better test would be :
    Code:
    if (number_id.replace(/\s+/,'') == "") {
       //
    }
    Then the test will be valid even with invisible characters like spaces, carriage returns, line feeds or other tabulations...
    Last edited by 007julien; 03-27-2014 at 12:12 AM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    Or test for at least so many digits, and nothing but. In the UK mobile phone numbers start with 7.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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