Hi Rabbit & gits, thankyou for your prompt reply. Thanks!
OK so Rabbit, you say that getElementById picks up the current state of the controls on the webpage. Well, what I am attempting to do is test the value of the "checked" attribute on a checkbox and run the method that contains this logic, from a button on my webpage.
The testing logic method for the checkbox in my .js file is:
-
function TestInpatientBenefitsTry2() {
-
-
// test that we are calling this correctly
-
alert('Test run started');
-
-
var inpatientHarmony5M = "12644_HasBenefit_0";
-
var myObjHarmony5M = txt.getElementById(inpatientHarmony5M).attributes("checked");
-
-
var inpatientHarmony2M = "12581_HasBenefit_1";
-
var myObjHarmony2M = txt.getElementById(inpatientHarmony2M).attributes("checked");
-
-
if (myObjHarmony5M == "checked") {
-
alert('Harmony 2M is disabled \n because Harmony 5M is selected');
-
}
-
-
if (myObjHarmony2M == "checked") {
-
alert('Harmony 5M is disabled \n because Harmony 2M is selected');
-
}
-
-
if (myObjHarmony5M != "checked" || myObjHarmony2M != "checked") {
-
alert('No outpatient benefits are enabled because no inpatient benefit has been selected');
-
}
-
-
alert("Test Run Completed");
-
}
-
And, in case you want to see it, in my vbhtml web page, I call it like so:
-
@<input type="button" value="Run Tests" onclick='RunTests()' />
-
-
function RunTests()
-
{
-
TestInpatientBenefitsTry2();
-
}
-
The test still isn't working as expected - if I have the inpatientHarmony5M box checked then, I would expect to see the alert box; 'Harmony 2M is disabled \n because Harmony 5M is selected' and similarly, I would expect to see the second alert box in my code passage, for the Harmony 5M checkbox.
If I take out the 2nd and 3rd if statement, and have the Harmony 2M checkboxes checked, the relevant checkbox is displayed. However, if I put all three if statements in the function to check the attributes of the checkboxes given the 3 possible scenarios, then none of the messages are displaying.
So I would like to know 2 things:
1. Am I calling and checking the attribute values of the checkboxes correctly in the condition of my 'if' statements?
2. Have I structured my if statements correctly or am I missing some logic?
Thanks again
Matt