如何在javascript中的onchange事件中使textbox属性为true? [英] How to make textbox attribute true in onchange event in javascript?

查看:88
本文介绍了如何在javascript中的onchange事件中使textbox属性为true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在javascript中更改textbox1时使textbox2为必填(true)?

how to make textbox2 required(true) onchange of textbox1 in javascript?

Please let me know on this.

推荐答案

最简单的解决方案是在提交表单之前先对其进行验证.
在提交表单时调用javascript方法-
首先检查TextBox1的值是否为空.如果它有一些值,它将检查第二个TextBox的值.如果为空,将发出警报或错误消息.

您可以使用以下语法在JavaScript的TextBox中获取文本-
var TextBoxValue = document.getElementById("TextBoxID").value;

我将把剩下的编写代码的工作留给您.如果您有任何问题,请告诉我.
希望对您有所帮助!
The simplest solution would be to validate the form before you submit it.
Call a javascript method on submit of the form which will -
First check if the value of TextBox1 is empty or not. In case it has some value, it will check the value of second TextBox. If it is empty, an alert or error message will be fired.

You get the text in a TextBox in JavaScript using this syntax -
var TextBoxValue = document.getElementById("TextBoxID").value;

I will leave the rest part of writing code to you. Let me know if you have any issues.
Hope it helps!


<input type=checkbox id=ch>

<script>

    document.getElementById("ch").checked = true;

</script>


这篇关于如何在javascript中的onchange事件中使textbox属性为true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆