我有以下问题。我有以下表格
<form name="asianCalculator" action="" id="asianCalculator" onsubmit="return testfunction(this.form);">
<div class="form_row">
<div class="form_label">
Επιλογή Handicap
</div>
<div class="form_input">
enter code here
<div class="asian_selector_big">
<select class="selectbox_big" name="handicap" id="handicap">
<option value="-4.00">-4.00</option>
<option value="-3.75">-3.75 (-3.5, -4.0)</option>
<option value="-3.50">-3.50</option>
<option value="-3.25">-3.25 (-3.0, -3.5)</option>
<option value="-3.00">-3.00</option>
<option value="-2.75">-2.75 (-2.5, -3.0)</option>
<option value="-2.50">-2.50</option>
<option value="-2.25">-2.25 (-2.0, -2.5)</option>
<option value="-2.00">-2.00</option>
<option value="-1.75">-1.75 (-1.5, -2.0)</option>
<option value="-1.50">-1.50</option>
<option value="-1.25">-1.25 (-1.0, -1.5)</option>
<option value="-1.00">-1.00</option>
<option value="-0.75">-0.75 (-0.5, -1.0)</option>
<option value="-0.50">-0.50</option>
<option value="-0.25">-0.25 (0.0, -0.5)</option>
<option value="0.00" selected="selected">0.0 (level)</option>
<option value="0.25">+0.25 (0.0, +0.5)</option>
<option value="0.50">+0.50</option>
<option value="0.75">+0.75 (+0.5, +1.0)</option>
<option value="1.00">+1.00</option>
<option value="1.25">+1.25 (+1.0, +1.5)</option>
<option value="1.50">+1.50</option>
<option value="1.75">+1.75 (+1.5, +2.0)</option>
<option value="2.00">+2.00</option>
<option value="2.25">+2.25 (+2.0, +2.5)</option>
<option value="2.50">+2.50</option>
<option value="2.75">+2.75 (+2.5, +3.0)</option>
<option value="3.00">+3.00</option>
<option value="3.25">+3.25 (+3.0, +3.5)</option>
<option value="3.50">+3.50</option>
<option value="3.75">+3.75 (+3.5, +4.0)</option>
<option value="4.00">+4.00</option>
</select>
</div>
</div>
<div class="clear"></div>
</div>
<div class="form_row">
<div class="form_label">
Επιλλογή ομάδας
</div>
<div class="form_input">
<div class="asian_selector_big">
<select class="selectbox_big" name="selection" id="selection">
<option value="h">Γηπεδούχος</option>
<option value="a">Φιλοξενούμενη</option>
</select>
</div>
</div>
<div class="clear"></div>
</div>
<div class="form_row">
<div class="form_label">
<label for="odds">
Απόδοση σημείου
</label>
</div>
<div class="form_input">
<input class="asian_input" name="odds" type="text" id="odds" value="1.91" />
</div>
<div class="clear"></div>
</div>
<div class="form_row">
<div class="form_label">
<label for="wager">
Ποντάρισμα
</label>
</div>
<div class="form_input">
<input class="asian_input" name="wager" type="text" id="wager" value="100" />
</div>
<div class="clear"></div>
</div>
<div class="form_row">
<div class="form_label">
Επιλογή κέρδους
</div>
<div class="form_input">
<div class="asian_selector_big">
<select class="selectbox_big" name="calcOption" id="calcOption">
<option value="s" selected="selected" onclick="toggleSpecificOptions(true)">Αποτέλεσμα</option>
<option value="a" onclick="toggleSpecificOptions(false)">Γενικά</option>
</select>
</div>
</div>
<div class="clear"></div>
</div>
<div id="form_row_hide">
<div class="form_label">
Αποτέλεσμα
</div>
<div class="form_input">
<div class="asian_selector_small">
<select class="selectbox_small" name="homeScore" id="homeScore">
<option selected="selected">0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</div>
<div id="versus">-</div>
<div class="asian_selector_small">
<select class="selectbox_small" name="awayScore" id="awayScore">
<option selected="selected">0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</div>
</div>
<div class="clear"></div>
</div>
<input type="submit" value="Calculate" />
</form>
我想验证2个输入字段,因此我使用http://livevalidation.com/中的livevalidation来摆脱那些丑陋的“警报”。
我现在的问题是我想在testfunction()中做一些计算,我不希望提交表单。我可以使用type =“button”而不是“submit”,但这样生活验证将无效。
所以当我输入类似
的内容时function testfunction (myform) {
var odds = myform.odds.value;
var handicap = myform.handicap.options[myform.handicap.selectedIndex].value;
//much more code here
return false; }
它忽略了返回false并且表单被提交。如果我没有从表单获得输入的任何东西它工作正常。那么如何在提交时获得输入并返回false以便表单不会被提交?
答案 0 :(得分:1)
你能做的就是
<input type="submit" value="Calculate" onclick="return (testfunction ('yourform'));" />
它会在调用函数时返回函数的返回值(false)。