lschena
08-18-2011, 03:08 PM
Hello,
Thank you for the help with my previous post here. I totally understand what it is going on and how and why I fixed it to work because of your great explanation and skillful teaching!! Way better than my teacher at bight school!! He is not a good teacher unfortunately (I am in a certif. program in web design)
So now I want to list several features of various cappaccino machines and another category of cost - budget, moderate and expensive. By clicking on this it will result in a box listing one or two, of a total of three or four machines that one could buy with their particular choices.
The most important thing is not what the script does but I need to understand why it does this. How would adding the functionality I want be done? If it is too complicated to explain, I am very happy with what it does now and can expand on it as is, and explain why it works. If you can go over how to make it do more, all the better. Thank you so much for making it make sense!! Excellent job! - Laurie
Here is what I have now:
[CODE]
<script type="text/javascript">
var machineTypeIndex = 0;
function machineType_onclick(machIndex)
{
var returnValue = true;
if (machIndex == 1)
{
returnValue = false;
alert("Sorry that machine is currently unavailable");
// Next line works around a bug in IE that doesn’t cancel the
// Default action properly
document.form1.machineType[machineTypeIndex].checked = true;
}
else
{
machineTypeIndex = machIndex;
}
return returnValue;
}
function btnCheck_onclick()
{
var controlIndex;
var element;
var numberOfControls = document.form1.length;
var compSpec = "Your chosen cappaccino machine is ";
compSpec = compSpec + document.form1.machineType[machineTypeIndex].value;
compSpec = compSpec + "\nWith the following additional features\n";
for (controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
{
element = document.form1[controlIndex];
if (element.type == "checkbox")
{
if (element.checked == true)
{
compSpec = compSpec + element.value + "\n";
}
}
}
alert(compSpec);
}
</script>
</head>
<body>
<form action="" name="form1">
<p>
Tick all of the features you want included on your machine
</p>
<table>
<tr>
<td>
Delonghi Cappaccino Machine
</td>
<td>
<input type="checkbox" name="chkCoffee" value="Delonghi" />
</td>
</tr>
<tr>
<td>
Solis Ultra Touch
</td>
<td>
<input type="checkbox" name="chkEspresso" value="Solis" />
</td>
</tr>
</table>
<p>
Select the price range you would like
</p>
<table>
<tr>
<td>
<input type="radio" name="machineType" checked="checked"
onclick="return machineType_onclick(0)" value="budget" />
</td>
<td>
Budget
</td>
<td>
<input type="radio" name="machineType" value="expensive"
onclick="return machineType_onclick(1)" />
</td>
<td>
Expensive
</td>
</tr>
</table>
<input type="button" value="Check Form" name="btnCheck"
onclick="return btnCheck_onclick()" />
</form>
[CODE]
Thank you for the help with my previous post here. I totally understand what it is going on and how and why I fixed it to work because of your great explanation and skillful teaching!! Way better than my teacher at bight school!! He is not a good teacher unfortunately (I am in a certif. program in web design)
So now I want to list several features of various cappaccino machines and another category of cost - budget, moderate and expensive. By clicking on this it will result in a box listing one or two, of a total of three or four machines that one could buy with their particular choices.
The most important thing is not what the script does but I need to understand why it does this. How would adding the functionality I want be done? If it is too complicated to explain, I am very happy with what it does now and can expand on it as is, and explain why it works. If you can go over how to make it do more, all the better. Thank you so much for making it make sense!! Excellent job! - Laurie
Here is what I have now:
[CODE]
<script type="text/javascript">
var machineTypeIndex = 0;
function machineType_onclick(machIndex)
{
var returnValue = true;
if (machIndex == 1)
{
returnValue = false;
alert("Sorry that machine is currently unavailable");
// Next line works around a bug in IE that doesn’t cancel the
// Default action properly
document.form1.machineType[machineTypeIndex].checked = true;
}
else
{
machineTypeIndex = machIndex;
}
return returnValue;
}
function btnCheck_onclick()
{
var controlIndex;
var element;
var numberOfControls = document.form1.length;
var compSpec = "Your chosen cappaccino machine is ";
compSpec = compSpec + document.form1.machineType[machineTypeIndex].value;
compSpec = compSpec + "\nWith the following additional features\n";
for (controlIndex = 0; controlIndex < numberOfControls; controlIndex++)
{
element = document.form1[controlIndex];
if (element.type == "checkbox")
{
if (element.checked == true)
{
compSpec = compSpec + element.value + "\n";
}
}
}
alert(compSpec);
}
</script>
</head>
<body>
<form action="" name="form1">
<p>
Tick all of the features you want included on your machine
</p>
<table>
<tr>
<td>
Delonghi Cappaccino Machine
</td>
<td>
<input type="checkbox" name="chkCoffee" value="Delonghi" />
</td>
</tr>
<tr>
<td>
Solis Ultra Touch
</td>
<td>
<input type="checkbox" name="chkEspresso" value="Solis" />
</td>
</tr>
</table>
<p>
Select the price range you would like
</p>
<table>
<tr>
<td>
<input type="radio" name="machineType" checked="checked"
onclick="return machineType_onclick(0)" value="budget" />
</td>
<td>
Budget
</td>
<td>
<input type="radio" name="machineType" value="expensive"
onclick="return machineType_onclick(1)" />
</td>
<td>
Expensive
</td>
</tr>
</table>
<input type="button" value="Check Form" name="btnCheck"
onclick="return btnCheck_onclick()" />
</form>
[CODE]