Solved

How to use Javascript to allow only quarter increments such as .25, .5, .75, and .0

Posted on 2011-02-25
12
725 Views
Last Modified: 2012-05-11
My HR Department wants to only allow quarter hour increments on an Acrobat form. I see it allows for custom Javascript validation. How can I use Javascript to allow only quarter increments on the end of the string such as .25, .5, .75, and .0
0
Comment
Question by:smetterd
  • 6
  • 4
  • 2
12 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 34980903
This function will do what you need:


function bump(num) {
    return num += .25;
}

Open in new window

0
 
LVL 2

Author Comment

by:smetterd
ID: 34981049
Okay, but how would I enter is in to the acrobat field as a custom validation script where the form field is names "HOURSRow1" without the quotes?
0
 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
ID: 34981152
Can you add

onclick="bump(this);"

to the form field declaration?

Change the function to:


function bump(obj) {
    if (obj.value) {
        
        var num = obj.value;
        
        if (isNaN(num) {
            return ""; // Not a number
        }
        else {
            return parseFloat(obj.value) += .25;
        }
    }
    else {
        return ""; // No VALUE attribute
    }
}

Open in new window

0
 
LVL 2

Author Comment

by:smetterd
ID: 34982748
The only triggers I see are as follows

 Triggers
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34983896
When do you want the value increased?
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 34986171

Try something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26847810.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript"> 

jQuery(document).ready(function() {

  $("#check").click( checkQuarter );
  
});

function checkQuarter() {
  var value = parseFloat( $("#HOURSRow1").val() );
  var isValid = ( parseInt( value * 4 ) == value * 4 );

  alert( isValid );
}

</script>
</head>
<body>

  <input id="HOURSRow1" />
  <input id="check" value="Check" type="button" />

</body>
</html>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 29

Expert Comment

by:Badotz
ID: 34986281
jQuery? Really? Hammer this thumbtack with a flaming meteorite the size of Texas?
0
 
LVL 20

Expert Comment

by:Proculopsis
ID: 34986418

<!-- jQuery? Really? Hammer this thumbtack with a flaming meteorite the size of Texas? -->

<form>
  <input id="HOURSRow1" />
  <input id="check" value="Check" type="button" onclick="alert( ( parseInt( this.form['HOURSRow1'].value * 4 ) == this.form['HOURSRow1'].value * 4 ) && !isNaN( parseFloat( this.form['HOURSRow1'].value ) ) );" />
</form>
0
 
LVL 2

Author Comment

by:smetterd
ID: 34997485
Badotz, I would like the value to be checked when the user tabs out of that field in the PDF. Thx for the help.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34998309
Then use the onblure event:

onblur="bump(this);"

Not sure exactly how to specify this in Acrobat-speak, though...
0
 
LVL 2

Author Comment

by:smetterd
ID: 34998447
Thank you Badotz!
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34998500
No worries - glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now