function valForm() { // alert('IN'); var o = document.getElementById('order'); // CHECK DEFAULT var req = new Array('first_name', 'last_name', 'email', 'contribution'); //'donation_from', valid = true; for(var f in req) { o[req[f]].style.backgroundColor = '#fff'; // alert(o[req[f]].value); if (!o[req[f]].value) { o[req[f]].style.backgroundColor = '#ff0'; valid = false; } } // check total greater than 0 if (o["totalamount"].value == 0) { o["totalamount"].style.backgroundColor = '#ff0'; alert('You have not entered a contribution'); valid = false; } if ( ( o["donation_from"][0].checked == false ) && ( o["donation_from"][1].checked == false ) ) { alert('Please select one of the Donation From options'); document.getElementById('thedontype').style.backgroundColor = '#ff0'; valid = false; } if (!valid) {alert('Please complete any highlighted fields to continue');} return valid; } function numbersonly(e, decimal) { var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) { return true; } else if ((("0123456789").indexOf(keychar) > -1)) { return true; } else if (decimal && (keychar == ".")) { return true; } else return false; } function data_change(field) { var check = true; var value = field.value; //get characters //check that all characters are digits, ., -, or "" for(var i=0;i < field.value.length; ++i) { var new_key = value.charAt(i); //cycle through characters if(((new_key < "0") || (new_key > "9")) && !(new_key == "")) { check = false; break; } } //apply appropriate colour based on value if(!check) { field.style.backgroundColor = "red"; document.getElementById('badamount').style.display = 'inline'; } else { field.style.backgroundColor = "white"; document.getElementById('badamount').style.display = 'none'; // CALCULATE WHICH CHECKBOX IS SELECTED //var o = document.getElementById('order'); var theamount = Number(document.getElementById("contribution").value); //document.getElementById("totalamount").value = theamount; } } function setCheckedValue(radioObj, newValue) { if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) { radioObj.checked = (radioObj.value == newValue.toString()); return; } for(var i = 0; i < radioLength; i++) { radioObj[i].checked = false; if(radioObj[i].value == newValue.toString()) { radioObj[i].checked = true; } } }