使用javascript从特定的选中单选按钮在表单提交时创建页面重定向
马上为这段看起来很差劲的代码道歉。我需要一些帮助创建页面重定向时,一个表单提交,而一个特定的单选按钮组合被选中或选中。我正在处理的实际表单已经设置好,因此需要使用javascript。我有一个简单的例子来说明我到目前为止所做的工作使用javascript从特定的选中单选按钮在表单提交时创建页面重定向,javascript,html,forms,Javascript,Html,Forms,马上为这段看起来很差劲的代码道歉。我需要一些帮助创建页面重定向时,一个表单提交,而一个特定的单选按钮组合被选中或选中。我正在处理的实际表单已经设置好,因此需要使用javascript。我有一个简单的例子来说明我到目前为止所做的工作 <html> First Question?<br> <label>Yes<input type="radio" name="1" id="1" value="1"><br></label> &l
<html> First Question?<br>
<label>Yes<input type="radio" name="1" id="1" value="1"><br></label>
<label>No<input type="radio" name="2" id="2" value="2"><br></label>
Second Question?<br>
<label>Yes<input type="radio" name="3" id="3" value="3"><br></label>
<label>No<input type="radio" name="4" id="4" value="4"><br></label>
</br>
<input type="submit">
<script>
onFormSubmit: (function sum($form) {
var ab = document.getElementById("1");
var bc = document.getElementById("2");
var cd = document.getElementById("3");
var de = document.getElementById("4");
var ef = (ab) && (bc);
var fg = (ab) && (cd);
var gh = (ab) && (de);
if ($form.find("ef").prop("checked")) {
window.location.href = "url 1"
} else if ($form.find("fg").prop("checked")) {
window.location.href = "url 2"
} else if ($form.find("gh").prop("checked")) {
window.location.href = "url 3"
else {
window.location.href = "url 4"
}
});
</script>
</html>
第一个问题?
是
否
第二个问题?
是
否
onFormSubmit:(函数和($form){
var ab=document.getElementById(“1”);
var bc=document.getElementById(“2”);
var cd=document.getElementById(“3”);
var de=document.getElementById(“4”);
var ef=(ab)和(bc);
var fg=(ab)和(cd);
var gh=(ab)和(de);
如果($form.find(“ef”).prop(“checked”)){
window.location.href=“url 1”
}否则如果($form.find(“fg”).prop(“checked”)){
window.location.href=“url 2”
}否则如果($form.find(“gh”).prop(“checked”)){
window.location.href=“url 3”
否则{
window.location.href=“url 4”
}
});
我已经尝试了一些事情。这就是我结束的地方。每次我都设法让一些东西工作,但它只是定义了第一个id,而不是基于所选id的组合等。我想最终扩展更多问题的形式,但我的主要目标是先让它工作
非常感谢您提前提供的帮助,并再次为javascript的这个无力的借口表示歉意。这是您正在寻找的训练。请查看代码片段,如果您有任何问题,请告诉我
函数onFormSubmit($form){
event.preventDefault();
var ab=document.getElementById(“1”);
var bc=document.getElementById(“2”);
var cd=document.getElementById(“3”);
var de=document.getElementById(“4”);
如果(ab.选中和bc.选中){
console.log('url 1');
window.location.href=“url 1”;
}else if(ab已选中和cd已选中){
log('url 2');
window.location.href=“url 2”;
}否则如果(ab检查和de检查){
console.log('url 3');
window.location.href=“url 3”;
}否则{
log('url 4');
window.location.href=“url 4”};
}
第一个问题?
是
否
第二个问题?
是
否