我正在尝试创建一个表格,该表格包含生日,将所有数字相加,然后使用结果来查询数据库并显示结果。总和必须是 1 到 22 之间的数字,才能从数据库中进行选择。
我有表单按钮来触发函数 getBirthCard,但是单击它只是将表单输入的值吐到 URL 中。
谁能给我一个想法,什么没有正确编码才能使其正常工作?谢谢,麻烦您了!
<script language="JavaScript" type="text/javascript">
function getBirthCard() {
var month = lpn.month.value;
var day = lpn.day.value;
var Byear = lpn.year.value;
var century = Byear.substring (0,2);
var year = Byear - century*100;
sum = parseInt(day) + parseInt(month) + parseInt(century) + parseInt(year);
reduce();
results(sum);
}
function reduce(){
var first; // first one or two digits
var last; // last digit
var sumStr = "" + sum;
// while number is bigger than 22
while (sum > 22) {
// if it is a three digit number
if (sum > 99) {
first= sumStr.substring(0,2);
last= sumStr.substring(2);
sum = parseInt(first) + parseInt(last);
sumStr = "" + sum;
// if it is a two digit number
} else {
first= sumStr.substring(0,1);
last= sumStr.substring(1);
sum = parseInt(first) + parseInt(last);
sumStr = "" + sum;
}
} // end while
} // end reduce
}
function results()
{
window.location.assign("http://arcanabazaar.com/results.php?id=' + sum")
}
</script>
这是我正在使用的表格:
<form class="form-inline" action="" name="lpn" method="GET">
<input type="text" id="month" name="month" placeholder="08">
<input type="text" id="day" name="day" placeholder="20">
<input type="text" id="year" name="year" placeholder="1987">
<br><br>
<button type="submit" onclick="getBirthCard()" class="btn btn-large">What's My Card?</button>
</form>