#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    18
    Rep Power
    0

    Text box accept only multiple on 0.25 values.


    hi,
    i got a problem.i have a text box. it should accept 0.25 multiples means 0.25,0.50,0.75,1.00,1.25,1.50 like that.

    i have got requirement like this.

    15 Minutes - 0.25
    30 Minutes - 0.50
    45 Minutes - 0.75
    60 Minutes - 1.00
    75 Minutes - 1.25 and so on...


    can any one help me on this
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    You could try something like this using jQuery:

    Html:
    Code:
    <label for="myTextBox">Enter a value:</label>
    <input id="myTextBox" type="text" />
    <button id="myButton">Go</button>
    jQuery:
    Code:
    $("#myButton").click(function() {
      var num = $("#myTextBox").val();
        if (num.length == 0 || isNaN(num)) {
            alert("Value is empty or not a number");
            return;
        }
        
        if (num % 0.25 == 0) {
            var mins = num * 60;
            alert("Value is a multiple of 0.25: " + num + " equals " + mins + " minutes" );
        }
        else {
            alert("Value is not a multiple of 0.25, try again");
        }
    });

IMN logo majestic logo threadwatch logo seochat tools logo