我尝试使用某些条件逻辑编写表单。我会给你们一个例子,我想做什么。
问题1:您有保修表吗?
如果访客按了是,我想显示以下内容:
问题2:购买日期?
我已经获得了以下代码:
代码问题1
<div class="form-section-content2">
<div class="first-label-column-1-grey">
<div class="form-content">
Garantie bewijs meegeleverd *
</div>
</div>
<div class="first-label-column-2-grey">
<div class="form-content">
<input class="form-field" type="radio" name="garantie" value="ja"> Ja</br>
<input class="form-field" type="radio" name="garantie" value="nee"> Nee
</div>
</div>
</div>
代码问题2
<div class="form-section-content1">
<div class="first-label-column-1-white">
<div class="form-content">
Aanschafdatum *
</div>
</div>
<div class="first-label-column-2-white">
<div class="form-content">
<input class="form-field-text" type="text" name="aanschafdatum">
</div>
</div>
</div>
我尝试使用php和javascript,但无法完成。如果你们能帮助我会很棒。
答案 0 :(得分:2)
只要单击单选按钮,就可以使用JavaScript onChange
事件来运行函数。然后,您可以根据点击的按钮显示<div>
。
function displayQuestion(answer) {
document.getElementById(answer + 'Question').style.display = "block";
if (answer == "yes") { // hide the div that is not selected
document.getElementById('noQuestion').style.display = "none";
} else if (answer == "no") {
document.getElementById('yesQuestion').style.display = "none";
}
}
&#13;
<form name="feedback" action="javascript:void(0)">
<label>
<input type="radio" id="yes" name="yesOrNo" value="yes" onchange="displayQuestion(this.value)" />Yes</label>
<label>
<input type="radio" id="no" name="yesOrNo" value="no" onchange="displayQuestion(this.value)" />No</label>
<div id="yesQuestion" style="display:none;"><br/>
Why did you choose yes?
<input type="text" placeholder="answer here . . . " />
</div>
<div id="noQuestion" style="display:none;"><br/>
Why did you choose no?
<input type="text" placeholder="answer here . . . " />
</div>
<br/><br/><input type="submit">
</form>
&#13;
希望有所帮助!