Greetings,
I maintain a web page for the engineering department where I work and I was trying to make a humorous tool for the web page. Basically it is a form with three categories... Good/Fast/Cheap. Good meaning - a work product that is correct/accurate/etc. Fast meaning on or ahead of schedule. Cheap meaning on or under budget The user would select two of the three "work product" categories using checkboxes and then click on the submit button for the answer. Depending on what they checked would determine the output. If they didnt' check enough categories they would get an answer telling them to select another and resubmit. If they selected all three they would be given an answer indicating they must be in management because they want the job done good, fast and cheap. The truth is you can only have two categories... The work can be done good and fast but it won't be cheap, good and cheap but it won't be fast or fast and cheap but it won't be good. You get the idea.
I'm looking for some help from some javascript "mandarins". I'm struggling trying to figure out how to obtain a value from the checkbox in a form and then using that data with some if statements to output the right answer. Note that I can't use a <FORM> tag on the corporate server so the form is designated as "all".
Please accept my apologies if the code I have below is garbage - I'm a self taught html programmer and only dabble in javascript (which I find somewhat confusing).
Thanks in advance for any help anyone can provide.
Regards,
Chuck Bruce
Here's what I have (that's currently not working):
<SCRIPT LANGUAGE="JavaScript">
function calculate()
{
var g = document.all.g.value;
var f = document.all.f.value;
var c = document.all.c.value;
var g = 0;
var f = 0;
var c = 0;
if ( good == 1) { var g = 1 };
if ( fast == 3) { var f = 3 };
if ( cheap == 5) { var c = 5 };
var s = g + f + c;
if (var s == 0) { var ans = "Hey!, you need to select two categories."};
if (var s == 1) { var ans = "Hey!, you need to select another category."};
if (var s == 3) { var ans = "Hey!, you need to select another category."};
if (var s == 4) { var ans = "It'll be good and fast, but it won't be cheap!"};
if (var s == 5) { var ans = "Hey!, you need to select another category."};
if (var s == 6) { var ans = "It'll be good and cheap, but it won't be fast!"};
if (var s == 8) { var ans = "It'll be fast and cheap, but it won't be good!"};
if (var s == 9) { var ans = "You must be management - you want it good, fast *and* cheap!"};
document.all.ans.value=ans;
}
</SCRIPT>
<TABLE>
<TR>
<TD><BIG><B>Check two of the three options below and then click "Submit"</B></BIG>
<hr no shade size="2">
</TD>
</TR>
<TR>
<TD align="left" valign="top">
<INPUT TYPE="checkbox" NAME="good" value="1"> Good (i.e., accurate/correct/etc.)<br>
<INPUT TYPE="checkbox" NAME="fast" value="3"> Fast (i.e., on/ahead of schedule)<br>
<INPUT TYPE="checkbox" NAME="cheap" value="5"> Cheap (i.e., on/under budget)</TD>
</TR>
<TR>
<TD>
</TD>
</TR>
<TR>
<TD align="center" valign="top">
<INPUT TYPE=button VALUE="Submit" onClick="calculate()">
</TD>
</TR>
<TR>
<TD align="center">
<INPUT TYPE="text" NAME="ans" SIZE="100"><br>
</TD>
</TR>
</TABLE>