我正在创建一个表单,该表单将有多个项目可供选择并签入(添加/增加)和签出(减/减),它仅在笔记本电脑变量等于 1 时才有效。我想设置总金额一个项目,然后他们选择的任何选项都会增加或减少与该项目相关联的变量。我也想不出一种方法来确保每次关闭并再次打开表单时变量都不会重置。
function updateCount (form) {
//need to figure out way for count to not reset to total when closing
form
//only works when set to 1
var laptop=1;
if (form.option1.checked && form.optionin.checked) {
laptop++;
alert ("Your response has been recorded");
}
if (form.option1.checked && form.optionout.checked) {
laptop--;
alert ("Your response has been recorded");
}
if (form.option1.checked && form.optionout.checked && laptop===0) {
alert ("Item currently unavailable, choose another item");
}}
<h1>CS Equipment Renatal Form</h1>
<form>
<!--top of form with name and line break for text, don't need
anything with the Name: -->
Name:<br>
<!--creating the variable type for textfield and the name of it which
is fullname-->
<input type="text" name="fullname"><br>
<br>
<!--email textfield with line break after meaning new line-->
OU Email:<br>
<input type="email" name="ouemail"><br>
<br>
<!--doing the checkboxes for rental types with id since the id is
used in the script -->
Equipment Rental Type<br>
Laptop <input type="checkbox" name="option1" value="laptop"
id="option1"><br>
Tablet <input type="checkbox" name="option2" value="tablet"
id="option2"><br>
Monitor <input type="checkbox" name="option3" value="monitor"
id="option3"><br>
Camera <input type="checkbox" name="option4" value="camera"
id="option4"><br>
<br>
噜噜哒
相关分类