选择禁用选项的过帐值

时间:2018-10-05 03:57:58

标签: html post

当用户不选择选项时,我想发布值,但是

<select name="nowEdu_level" class="form-control">
    <option disabled="" selected="" value="0"></option> //this is the Disable Option
    <option value="level_bacDe">Bachelor Degree</option>
    <option value="level_masDe">Master Degree</option>
    <option value="level_other">Other Graduate</option>
</select>

但是当我提交此帖子的值是“ None”时,我想在用户未选择该选项时发布“ 0”

请帮助我,我很新手

3 个答案:

答案 0 :(得分:0)

当您点击发布时,您将获得0值,并已使用getElementById通过下拉列表ID提取标书。

function myFunction() {
    var x = document.getElementById("mySelect").value;
    document.getElementById("demo").innerHTML = x;
}
<form>
Select your favorite fruit:
<select id="mySelect" name="nowEdu_level" class="form-control">
<option disabled="" selected="" value="0"></option> //this is the Disable Option
<option value="level_bacDe">Bachelor Degree</option>
<option value="level_masDe">Master Degree</option>
<option value="level_other">Other Graduate</option>
</select>
</form>

<p>Click the button to return the value of the selected fruit.</p>

<button type="button" onclick="myFunction()">Post</button>

<p id="demo"></p>

答案 1 :(得分:0)

function myFunction() {
	debugger;
	var e = document.getElementById("mySelect");
	var strUser = e.options[e.selectedIndex].value;
	console.log(strUser);
	}
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
  <form>
Select your favorite fruit:
<select id="mySelect" name="nowEdu_level" class="form-control">
<option disabled="" selected="" value="0" ></option> //this is the Disable Option
<option value="level_bacDe">Bachelor Degree</option>
<option value="level_masDe">Master Degree</option>
<option value="level_other">Other Graduate</option>
</select>
</form>

<p>Click the button to return the value of the selected fruit.</p>
<button type="button" onclick="myFunction()">Post</button>

<p id="demo"></p>
</body>
</html>

这将为您提供默认所选项目的值。

答案 2 :(得分:0)

<select name="nowEdu_level" class="form-control">
    <option disabled selected value="">-- Education Level -- </option> //this is the Disable Option
    <option value="level_bacDe">Bachelor Degree</option>
    <option value="level_masDe">Master Degree</option>
    <option value="level_other">Other Graduate</option>
    <option value="0">None Above</option>
</select>

您可以这样做