如何提醒文本框的值

时间:2016-09-06 06:55:14

标签: javascript

我试图在JavaScript中警告表单文本框的值,但它不起作用,而我的其他表单具有相同的JavaScript代码,它们正常工作。我花了很多时间来解决这个问题,但没有成功。

<!DOCTYPE html>
<html>
    <head>
        <script>
        function call(){
            var siv=document.getElementById("siv")‌​.value;
            alert(siv);
        }
        </script>
    </head>
    <body>
        <form  name="alm" action="#" method="post" onSubmit="call();">
            <label>Province: </label><br>
            <select name="ProvinceDropDown" id="ProvinceDropDown">
                <option value="SelectProvince"> Please Select </option>
                <option value="Sindh" selected='selected'> Sindh </option>
            </select>
            <input type="text" value=""  id="siv" name="siv">
            <input type="submit" value="submit" >
        </form>
    </body>
</html>  

3 个答案:

答案 0 :(得分:2)

您的var siv = document.getElementById("siv").value;声明中有一些不常见的字符(除非您的编辑通知您,否则无法看到)。再次写(删除那些不常见的字符),你的代码就可以了。

&#13;
&#13;
function call() {
  var siv = document.getElementById("siv").value;
  alert(siv);
}
&#13;
<form name="alm" action="#" method="post" onSubmit="call();">
  <label>Province:</label>
  <br>
  <select name="ProvinceDropDown" id="ProvinceDropDown">
    <option value="SelectProvince">Please Select</option>
    <option value="Sindh" selected='selected'>Sindh</option>
  </select>
  <input type="text" value="" id="siv" name="siv">
  <input type="submit" value="submit">
</form>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

检查document.getElementById(&#34; id&#34;)。value;拼写。

答案 2 :(得分:2)

您的JavaScript代码有\ u200b(零宽度空间)

enter image description here

更新代码:

<!DOCTYPE html>
<html>
<head>
    <title>Stack Sample</title>
</head>
<script type="text/javascript">
    function call() {
  var siv = document.getElementById("siv").value;
  alert(siv);
}
</script>
<body>
    <form name="alm" action="#" method="post" onSubmit="call();">
  <label>Province:</label>
  <br>
  <select name="ProvinceDropDown" id="ProvinceDropDown">
    <option value="SelectProvince">Please Select</option>
    <option value="Sindh" selected='selected'>Sindh</option>
  </select>
  <input type="text" value="" id="siv" name="siv">
  <input type="submit" value="submit">
</form>
</body>
</html>