User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 426,329 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,306 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2984 | Replies: 2 | Solved
Join Date: Jun 2006
Posts: 2
Reputation: neophyteprogram is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neophyteprogram neophyteprogram is offline Offline
Newbie Poster

Help Processing Checkbox Information From A Form

  #1  
Jun 8th, 2006
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):

[HTML]
<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>
&nbsp;
</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>
[/HTML]
Last edited by tgreer : Jun 8th, 2006 at 10:51 am. Reason: Poster forgot/ignored code tags.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC