0
我是網絡開發新手。我有兩個按鈕的形式,我有一個JavaScript函數來驗證當它處於一種形式:表單驗證只需一個按鈕
function validateForm() {
var freq = document.forms["schedulerForm"]["frequency"].value;
if(freq == null || freq ==""){
alert("Please select a frequency!");
return false;
}
var freqValue = document.forms["schedulerForm"]["frequencyValue"].value;
if (freqValue == null || freqValue == "") {
alert("Please enter a frequency value!");
return false;
}
var email = document.forms["schedulerForm"]["email"].value;
if (email == null || email == "") {
alert("Please add an email!");
return false;
}
}
和表單:(適用於問題的目的)
<form method="post" id="schedulerForm" onsubmit="return validateForm()">
<div class="controls">
<select id="frequency" name="frequency" class="form-control">
<option value="">Select a Frequency</option>
<option value="seconds">Seconds</option>
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
</select>
</div>
<input type="text" name="frequencyValue" id="frequencyValue">
<input autocomplete="off" class="input" id="email" type="text" placeholder="Enter an email" data-items="8">
<input type="submit" class="btn btn-primary" name="btnStart" value="Start Scheduler" onclick="testScheduler('start')"/>
<input type="submit" class="btn btn-primary" name="btnStop" value="Stop Scheduler" onclick="testScheduler('stop')"/>
</form>
據工作,函數驗證的作品,但我想限制這種驗證只是爲第一個按鈕,而不是爲其他,我想拿出第二個按鈕,但如果我這樣做,將不會提交表單。
任何幫助將不勝感激!
非常感謝!這個作品=) – fabrik
很高興我能幫忙! – BenG