我有一个下拉列表。当某人单击下拉列表中的“其他”选项时,会出现一个空白行,允许某人编写他或她自己的请求。我想创建一个警告框,以粗体字显示某人在空白行中所写的内容。我该怎么做呢?
这是我的代码:
<form action="">
<select name="requests" onchange ="checkIfOther();" id="dropDown1">
<option value="blank"></option>
<option value="good morning sir">Good Morning Sir</option>
<option value="temperature">The current temperature is _____ centigrade.</option>
<option value="other">Other</option>
</select>
</form>
</p>
<button onclick="myFunction()" value>Submit</button>
<div id="other" style="display:none">
<br><br><label>Optional Request: </label><input type="text" id="otherText"/>
</div>
</body>
</html>
<script>
function checkIfOther(){
a = document.getElementById("dropDown1");
if(a.value == "other")
document.getElementById("other").setAttribute("style","display:inline");
else
document.getElementById("other").setAttribute("style","display:none");
}
</script>
<script>
function myFunction(){
var x=document.getElementById("dropDown1");
alert("You have chosen: " + x.options[x.selectedIndex].text);
if(x.value == "other"){
b=document.getElementById("other");
alert("You have chosen: " + b.text); //what do I do?
}
}
</script>