onsubmit(return test();) 不返回 false;
我有以下问题。我有以下表单,
<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">
<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 个输入字段,因此我使用了此处找到的 livevalidation http://livevalidation.com/< /a> 摆脱那些丑陋的“警报”。
我现在的问题是我想在 testfunction()
中进行一些计算,但我不想提交表单。我可以使用 type="button"
而不是“提交”,但这样实时验证将无法工作。
因此,当我输入类似以下内容时:
function testfunction (myform) {
var odds = myform.odds.value;
var handicap = myform.handicap.options[myform.handicap.selectedIndex].value;
//much more code here
return false; }
它会忽略 return false 并提交表单。如果我没有任何东西可以从表单中获取输入,那么它就可以正常工作。那么如何获取提交时的输入并返回 false 以便表单不会被提交呢?
I have the following problem. I have the following form
<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">
<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>
I want to validate the 2 input fields so I used the livevalidation found here http://livevalidation.com/ to get rid of those ugly "alerts".
My problem now is that I want to do some calculations in testfunction()
and I don't want the form to be submitted. I could have used a type="button"
instead of "submit" but that way the livevalidation won't work.
So when I type something like:
function testfunction (myform) {
var odds = myform.odds.value;
var handicap = myform.handicap.options[myform.handicap.selectedIndex].value;
//much more code here
return false; }
It ignores the return false and the form is submitted. If I don't have anything that gets the input from the form it works fine. So how can I get the input on submit and return false so the form wont be submitted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的就是
在调用函数时返回函数的返回值 ( false )。
The thing you can do is
it will return the return ( false ) of the function while calling it.