Click to See Complete Forum and Search --> : prevent user from leaving textbox


rjusa
12-01-2003, 07:06 PM
I have the following:

**************************
<script language="JavaScript"><!--
function sum(objRef) {
var result = 0;
result += opener.document.forms[0].CndnFBpc.value - 0;
result += document.childForm1.cf1f.value - 0;
if (result > 100)
alert("Your total percent allocation exceeds 100%...please check your percent distributions");
}//--></script>


<input type="text" name="PercentPB1" value="$PercentPB1$" onkeyup="sum(this.value)">
**************************

So if a number e.g., 105 is entered, the alert pops up...this is good..but how do I prevent the user from leaving the textbox until a number <=100 is entered?

Thanks,
Ron

Khalid Ali
12-01-2003, 10:18 PM
use a combination of
on blur and focus()

rjusa
12-01-2003, 11:54 PM
Thanks Khalid, I've had the same idea and am still playing with it.

Here's my other dilema. I have this form ('PB1') that asks for a Beneficiary Percentage...if its over 100% the alert pops up

function sum(objRef) {
var result = 0;
result += document.PB1.PercentPB1.value - 0;

if (result > 100)
alert("Your total percent allocation exceeds 100%...please check your percent distributions");

Let's say they enter 50 and select the next Beneficiary option and Submit...new Beneficiary form comes up and again a % is asked for with the same alert scheme

function sum(objRef) {
var result = 0;
result += document.PB2.PercentPB2.value - 0;
if (result > 100)
alert("Your total percent allocation exceeds 100%...please check your percent distributions");

Not being the brightest crayon in the box I totally forgot that the sum of the %'s can't exceed 100...I tried something like

function sum(objRef) {
var result = 0;
result += opener.document.PB1.PercentPB1.value - 0;
result += document.PB2.PercentPB2.value - 0;
if (result > 100)
alert("Your total percent allocation exceeds 100%...please check your percent distributions");

in the second form but doesn't work. I've done this when the parent form opened a child but can't seem to quite get it in this instance. Any thoughts???

Thanks,
Ron