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
7
Medium Priority
?
161 Views
Last Modified: 2012-05-12
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
Comment
Question by:hidrau
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36986218
Use the mod function

if (fieldvalue % suggestedvalue == 0)
0
 
LVL 18

Assisted Solution

by:Cluskitt
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

by:hidrau
ID: 36987384
Friend, I don't know much JS, could you give an example how to create this function with a field?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Accepted Solution

by:
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

by:hidrau
ID: 36991742
thanks
0
 
LVL 1

Author Comment

by:hidrau
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

by:Cluskitt
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Article by: DanRollins
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

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question