禁用按钮,直到使用javascript在xslt中输入所有字段

时间:2016-05-26 14:26:07

标签: javascript html xml xslt

我在尝试禁用表单的提交按钮时遇到困难,直到所有字段都使用javascript在xslt中有值。

我正在使用xml文件并使用xslt将其转换为html。下面的代码显示了我想要做的事情。

Xslt文件

 <input id="save_choice" type="submit" value="Save Choice" />

错误说&#34;无法找到变量&#34;在第1行

(function() {
$('form > input').keyup(function() {     !can't find variable

    var empty = false;
    $('form > input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('#save_choice').attr('disabled', 'disabled');
    } else {
        $('#save_choice').removeAttr('disabled');
    }
});

})()

你能建议吗?谢谢

更新 下面是我正在使用的完整xslt文件和js文件。谢谢你提前帮助

  

  <head><script src="validation.js" type="text/javascript"/>


  </head>

  <body>
<h1>Give As You Earn</h1>

  <xsl:for-each select="data/options">

    <fieldset>
  <form name="form1" action="#">
      <label><xsl:value-of select="selectionText" /></label>
      <input type="text" name="{@inputName}" value="{@currentValue}" min="{@minimum}" max="{@maximum}" step="{@increment}"/>
      <span><xsl:value-of select="@suffix" /></span>
      <br/>
      <label>Please tell us which charity you wish to donate to</label>
      <input type="text" name="charity"></input>
      <br/>
      <input id="save_choice" type="submit" value="Save Choice" />
      <button><a href="#" target="_blank">Save Choice</a></button> 
  </form>
          </fieldset>
    </xsl:for-each>  

validation.js文件

(function() {
$('form > input').keyup(function() {

    var empty = false;
    $('form > input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('#save_choice').attr('disabled', 'disabled');
    } else {
        $('#save_choice').removeAttr('disabled');
    }
});

})()

0 个答案:

没有答案