Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

How can I accept only a value valid in my input?

Posted on 2011-10-18
Medium Priority
161 Views
Hello,

I have a input and I suggest a value, for example:

200

this field only must accept a multiply value from itself or divided by itself.

Then

It only can accept: 200 - 400 - 600 - 800 - 900 etc

thanks
Alex
0
Question by:hidrau
• 4
• 3

LVL 18

Expert Comment

ID: 36986218
Use the mod function

if (fieldvalue % suggestedvalue == 0)
0

LVL 18

Assisted Solution

Cluskitt earned 2000 total points
ID: 36986233
if (fieldvalue % suggestedvalue == 0 || fieldvalue % (suggestedvalue/2) == 0)
hadn't noticed the half part. I actually think just the last part is enough
0

LVL 1

Author Comment

ID: 36987384
Friend, I don't know much JS, could you give an example how to create this function with a field?
0

LVL 18

Accepted Solution

Cluskitt earned 2000 total points
ID: 36991354
Ok, try something like this:

Function Validate()
{
var MyValue = 200
var FieldValue = document.getElementById('MyTextBox').value
if (FieldValue % (MyValue / 2) == 0)
{
//valid code over here
}
else
{
//non-valid code over here
}
}
0

LVL 1

Author Closing Comment

ID: 36991742
thanks
0

LVL 1

Author Comment

ID: 37001742
Hi Cluskitt,

I notice that If I insert a value 500 it pass and it doesn't.

only value = my suggested value or multiply by itself

0

LVL 18

Expert Comment

ID: 37005049
I thought you meant only increments of the value or increments of half the value.
Just change the if to:
if (FieldValue % MyValue == 0 || FieldValue == MyValue / 2)
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll