没有一个变量被正确设置,现在我只是想通过引用按钮aQuote()来获取我的无线电选择的值以显示在字段中...然后我也希望能够从宽度和高度输入以创建到该字段的最终总输出,但我甚至无法实现第一件事。
var form = 1;
var chosen = document.inputForm.pack.value;
var width = 1;
var length = 1;
function aquote() {
document.getElementById("qprice").value = chosen ;
}
HTML:
<form id="inputForm" method="post" onSubmit="return validateForm();" action="submit.php">
<fieldset>
<label>First Name:</label>
<input type="text" name="first_name" />
<br />
<label>Surname:</label>
<input type="text" name="surname" />
<br />
<label>Mobile:</label>
<input type="text" name="mobile" />
<br />
<label>Email:</label>
<input type="text" name="email" /><br />
<div class="textRightform">
<label class="radio2">Pool package:</label><br>
<input type="radio" name="pack" value="2000"
checked="checked" />Rectanguluar
<input type="radio" name="pack" value="2500" onClick="getCheckedRadio()"/>Rectangluar with Spa
<input type="radio" name="pack" value="3000" />Round Pool
<input type="radio" name="pack" value="3500" />Round Pool with Spa<br><br>
<label>Length meters</label><input name="length" type="number" size="7" maxlength="4"><br>
<label>Width meters</label><input name="width" type="number" size="8" maxlength="4"><br><br>
<input name="quoteshow" type="text" value="" id="qprice" readonly /><br>
<input type="button" name="quote" id="qpress" value="Show Quote" onClick="aquote()"/>
</div> <br> <br>
<div class="buttonLeft">
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>" /> <!--Hidden token field-->
<input type="text" id="hp" name="hp" /> <!--Hidden honeypot field-->
<input type="submit" name="submit" value="Send form" />
<input type="reset" name="reset" value="Reset" />
</div>
</fieldset>
</form>
答案 0 :(得分:0)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<form id="inputForm" method="post" onSubmit="return validateForm();" action="submit.php">
<fieldset>
<label>First Name:</label>
<input type="text" name="first_name" />
<br />
<label>Surname:</label>
<input type="text" name="surname" />
<br />
<label>Mobile:</label>
<input type="text" name="mobile" />
<br />
<label>Email:</label>
<input type="text" name="email" /><br />
<div class="textRightform">
<label class="radio2">Pool package:</label><br>
<input type="radio" name="pack" value="2000"
checked="checked" />Rectanguluar
<input type="radio" name="pack" value="2500" onClick="getCheckedRadio()"/>Rectangluar with Spa
<input type="radio" name="pack" value="3000" />Round Pool
<input type="radio" name="pack" value="3500" />Round Pool with Spa<br><br>
<label>Length meters</label><input name="length" type="number" size="7" maxlength="4"><br>
<label>Width meters</label><input name="width" type="number" size="8" maxlength="4"><br><br>
<input name="quoteshow" type="text" value="" id="qprice" readonly /><br>
<input type="button" name="quote" id="qpress" value="Show Quote" onClick="aquote()"/>
</div> <br> <br>
<div class="buttonLeft">
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>" /> <!--Hidden token field-->
<input type="text" id="hp" name="hp" /> <!--Hidden honeypot field-->
<input type="submit" name="submit" value="Send form" />
<input type="reset" name="reset" value="Reset" />
</div>
</fieldset>
</form>
</body>
<script>
function aquote()
{
var radios = document.getElementsByName('pack');
var packValue =0;
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
packValue = radios[i].value;
}
}
alert(parseInt(packValue));
}
</script>
</html>