Wednesday, December 13, 2006

My users have been requesting a seemingly simple feature for a while now and I could not get it to work.
 
When they enter a value, they are prompted with a javascript confirm (Ok/Cancel) box if the value is over $1,000,000.  If the choose "OK", no problem.  But when they choose cancel, they wanted to be put back in that same field.  I should just be able to do the following:
 

function checkValue(){

if (document.getElementById('valuation ').value >= 1000000){

if (confirm("This value is over $1,000,000. Are you sure you meant to enter such a large value?")){

}

else {

document.getElementById('valuation').focus();

}

return false;

}

}

I was able to set focus to any field, except the one I just came from.  The only hack I was able to find was to set focus first to another field, then the field I came from and then use the follwing in my <input> statement.  

onFocus="this.select()"

Here is the javascript function I had to use:

function checkValuation(){

if (document.getElementById('valuation').value >= 1000000){

if (confirm("This value is over $1,000,000. Are you sure you meant to enter such a large value?")){

}

else {

document.getElementById('otherfield').focus();

document.getElementById('valuation').focus();

}

return false;

}

}

 
-------------------------------
David Mineer

No comments: