...

View Full Version : Getting a True Value for CheckBox - Javascript



isaaclloyd
03-22-2005, 06:09 PM
I am trying to figure out a "True" value as well as a "or" command. Any ideas? I need this script to run through the list and look to see if a value is true. Right now it looks through all 6 lines and if all are null, if they are it returns false. Heres the little bit:

if ((regExp1.exec(str_arrVals) == null)
(regExp2.exec(str_arrVals) == null) ||
(regExp3.exec(str_arrVals) == null) ||
(regExp4.exec(str_arrVals) == null) ||
(regExp5.exec(str_arrVals) == null) ||
(regExp6.exec(str_arrVals) == null)) {
alert("Please check a AA\nThank You");
return false;


Here's an idea of what I need: (Note that "CHECKED" does not actually work.)


if ((regExp1.exec(str_arrVals) == CHECKED)) {
return true;
}

else if ((regExp2.exec(str_arrVals) == CHECKED)) {
return true;
}

else{
alert("Please make a selection\nThank You");
return false;
}



Heres the whole actual code i'm working with:



<script type="text/javascript" language="javascript">
<!-- Begin
js_globalArr = new Array();

function js_buildArrStructure(f_cBoxArg){

if(f_cBoxArg.checked == true){

fn_cBoxArr = new Array();
fn_cBoxArr.push(f_cBoxArg.name);
fn_cBoxArr.push(f_cBoxArg.value);
js_globalArr.push(fn_cBoxArr);

} else{

fn_remVal = new Array();

fn_remVal.push(f_cBoxArg.name);
fn_remVal.push(f_cBoxArg.value);

if(js_globalArr.length == 1){

js_globalArr = js_globalArr.unshift();
js_globalArr = new Array();

} else{

for(var s_index = 0; s_index < js_globalArr.length; s_index++){
tmp_arr = new Array();
tmp_arr = js_globalArr[s_index];

if(tmp_arr.toString() == fn_remVal.toString()){

js_globalArr.splice(s_index, 1);

} else{

continue;
}
}
}
}
}


function cBoxValidate(){

var str_arrVals = "";
var regExp1 = new RegExp("UPSzGround", "g");
var regExp2 = new RegExp("UPSz2ndzDayzAir", "g");
var regExp3 = new RegExp("UPSzNextzDayzAir", "g");
var regExp4 = new RegExp("UPSz2ndzDayzAKxHI", "g");
var regExp5 = new RegExp("USPSzExpresszCanada", "g");
var regExp6 = new RegExp("USPSzGlobalzPriority", "g");

str_arrVals = js_globalArr.toString();

if ((regExp1.exec(str_arrVals) == null)
(regExp2.exec(str_arrVals) == null) ||
(regExp3.exec(str_arrVals) == null) ||
(regExp4.exec(str_arrVals) == null) ||
(regExp5.exec(str_arrVals) == null) ||
(regExp6.exec(str_arrVals) == null)) {
alert("Please check a AA\nThank You");
return false;

} else if(regExp2.exec(str_arrVals) == null) {
alert("Please check a DD\nThank You");
return false;
} else{
return true;
}
}
// END-->
</script>



Any comments or suggestions is greatly apreciated. Thanks for your time.

~Isaac Lloyd~

isaaclloyd
03-22-2005, 09:01 PM
I fixed my own answer in time. Here is what I needed:



<script type="text/javascript" language="javascript">
<!-- Begin

function valBox(){
if(document.getElementById("C1").checked==true){
return true;
}
else if(document.getElementById("C2").checked==true){
return true;
}
else{
alert('YAY!');
return false;
}
}

// END-->
</script>




~Isaac Lloyd~



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum