如何在空文本/数字字段

时间:2017-08-20 14:31:37

标签: javascript html

我希望在必填字段为空的情况下禁用HTML中的按钮。下面给出的代码是按钮所在的形式:



<form>
  Name*: <input type="text" size="20" name="name" /> <br /><br /> Surname: <input type="text" size="20" name="sur_name" /> <br />
  <br /><br /> Mobile number: <input type="tel" size="15" name="mob" /> <br /><br /> E-mail id*: <input type="Email" size="30" name="user_id" /> <br /><br /> Password*: <input type="Password" size="30" name="pw1" /> <br /><br /> Confirm Password*: <input
    type="password" size="30" name="pw2" /> <br /><br /><br /><br /> I accept the terms and conditions <input type="checkbox" name="t&c" /><br /><br />

  <input type="submit" class="btn btn-lg btn-primary" value="Sign up now" onclick=window.location.href="https://www.google.co.in/signup" />
</form>
&#13;
&#13;
&#13;

表单实际上是一个虚拟注册屏幕,但屏幕重定向是一个404错误屏幕,但我希望如果某些字段为空则禁用该按钮,并且如果密码的两个值是,则重新加载页面不同。

我完全不了解JS,所以请编辑代码以便参数清晰。

1 个答案:

答案 0 :(得分:0)

<input type="text" size="20" name="name" />替换为<input type="text" size="20" name="name" required/>

<input type="Email" size="30" name="user_id" />替换为<input type="Email" size="30" name="user_id" required/>

<input type="Password" size="30" name="pw1" />替换为<input type="Password" size="30" name="pw1" required/>

<input type="password" size="30" name="pw2" />替换为<input type="password" size="30" name="pw2" required/>