不需要禁用的文本字段 [英] Don't require disabled text field

查看:68
本文介绍了不需要禁用的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用必填文本字段来验证表单.它需要的工作方式是一个下拉菜单,其中有两个选项,基本和个性化.如果选择了基本",则文本字段将被禁用,并且不需要.如果选择了个性化,则将启用该字段,并且在继续之前必须先填写该字段.这种特殊形式适用于贝宝项目,但我也想将其用于其他形式.

这是我要使用的脚本.

I need to validate a form with a required text field. The way it needs to work is a drop down menu has two choices, Basic and Personalized. If basic is chosen the text field is disabled and should not be required. If personalized is chosen the field becomes enabled and should be required before proceeding. This particular form is for a paypal project, but I would like to use it for other forms as well.

This is the script I am trying to use.

<script type="text/javascript">
function findselected() {
var theobj=document.form.elements['amount'];
var seltxt=theobj.selectedIndex;
//alert(seltxt) test=gives the index number
   if (seltxt== 1) {
      document.form.os1.disabled=false;
//      return false;  // not sure this line is needed
   } else {
      document.form.os1.disabled=true;
//      return false;  // not sure this line is needed
   }
}
</script>




这是表格.




This is the form.

<form action="https://www.paypal.com/cgi-bin/webscr" method="POST" onClick="return displ();" name="form">
  <table width="440" align="center"><tr>
  <td height="25" align="left" valign="top">
  <select name="amount" onChange="findselected()" id="amount">
  <option value="Basic">Basic</option>
  <option value="Personalized">Personlized</option>
  </select>
  </td>
  </tr>
  <tr>
    <td height="25" align="left" valign="middle">
      Enter Your Personalized Text</td>
  </tr>
  <tr><td height="25" align="left" valign="top">
    <input type="text" id="txtField1" name="os1" disabled="true" style="width:350px">
  </span></td>
    </tr>
    <tr>
    <td height="40" align="right" valign="middle">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" />
    </td>
    </tr>
  </table>
  <p><img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_US/i/scr/pixel.gif" width="1" height="1"></p>
  </form>



我遇到的问题是我不知道该怎么做.我是编码的新手,所以我做了很多研究,但我找不到这个答案.



The problem I am having is that I don''t know how to do it. I am new to coding so I do a lot of research but I can''t find the answer to this one.

推荐答案

您没有指出什么问题你有吗?

我要做的第一件事就是看看 http://jquery.com/ [
You didn''t indicate what problems you were having?

This first thing I would do is have a look http://jquery.com/[^]. It will make working with JavaScript much easier.

If the issue is validating the field, then add an event to handle the submit and validate the field appropriately. I would even say rather than disabling the textbox just hide it when not necessary.

Also, tables layouts are very much frowned upon. You should look a table-less layout design.


这篇关于不需要禁用的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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