2012-12-13 51 views
-1

我正在使用asp.net mvc 3.到目前为止,我已经设法创建了一个datepicker。目前我在我看来有三个字段显示在下面的代码中。如何使用jQuery向TextBox插入值取决于另一个TextBox值

@Html.TextBoxFor(model => model.QuizNo, new{@class = "qno"}) 
    @Html.TextBoxFor(model => model.Mark, new { @class = "mk" }) 
    @Html.EditorFor(model => model.Pass, new { @class = "ps" }) 

最后一个有布尔值。这是我在TextBoxes中更改或设置值的脚本。

<script type="text/javascript"> 
$(document).ready(function() { 
    var qn = $(".qno :input").val(); 
    $(".mk").val(qn); 
    }); 
</script> 

我测试这个看看,当我输入在文本框QuizNo值我得到马克文本框的值。到目前为止,它从上面的代码中没有发生。

我是新的在asp.net mvc 3和jquery想检查在QuizNo中输入的值,如果它的134,144或156然后任何高于10的马克值是通过。

下面是输出的HTML代码。

<form action="/Home/CreateNewcert/4558" method="post"> <fieldset> 
     <legend>CPD Details</legend> 
      <table style="border:1px solid #ffffff;"> 

     <tr> 
     <td width="30%" style="border:1px solid #ffffff;"> 
     <div class="editor-label"> 
      <label for="QuizNo">QuizNo</label> 
     </div> 
     <div class="editor-field"> 

      <input class="qno" data-val="true" data-val-number="The field QuizNo must be a number." id="QuizNo" name="QuizNo" type="text" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="QuizNo" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="Received">Received</label> 
     </div> 
     <div class="editor-field"> 
      <select class="list-box tri-state" id="Received" name="Received"><option selected="selected" value="">Not Set</option> 
<option value="true">True</option> 
<option value="false">False</option> 
</select> 
      <span class="field-validation-valid" data-valmsg-for="Received" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="DateReceived">DateReceived</label> 
     </div> 
     <div class="editor-field"> 
      <input class="datefield" id="DateReceived" name="DateReceived" type="date" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="DateReceived" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="Paid">Paid</label> 
     </div> 
     <div class="editor-field"> 
      <select class="list-box tri-state" id="Paid" name="Paid"><option selected="selected" value="">Not Set</option> 
<option value="true">True</option> 
<option value="false">False</option> 
</select> 
      <span class="field-validation-valid" data-valmsg-for="Paid" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="DatePaid">DatePaid</label> 
     </div> 
     <div class="editor-field"> 
      <input class="datefield" id="DatePaid" name="DatePaid" type="date" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="DatePaid" data-valmsg-replace="true"></span> 
     </div> 
     </td> 
      <td width="30%" style="border:1px solid #ffffff;"> 

     </td> 

     <td width="30%" style="border:1px solid #ffffff;"> 
     <div class="editor-label"> 
      <label for="Mark">Mark</label> 
     </div> 
     <div class="editor-field"> 
      <input class="mk" id="Mark" name="Mark" type="text" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="Mark" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="MarkDate">MarkDate</label> 
     </div> 
     <div class="editor-field"> 
      <input class="datefield" id="MarkDate" name="MarkDate" type="date" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="MarkDate" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="Pass">Pass</label> 
     </div> 
     <div class="editor-field"> 
      <select class="list-box tri-state" id="Pass" name="Pass"><option selected="selected" value="">Not Set</option> 
<option value="true">True</option> 
<option value="false">False</option> 
</select> 
      <span class="field-validation-valid" data-valmsg-for="Pass" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="Printed">Printed</label> 
     </div> 
     <div class="editor-field"> 
      <select class="list-box tri-state" id="Printed" name="Printed"><option selected="selected" value="">Not Set</option> 
<option value="true">True</option> 
<option value="false">False</option> 
</select> 
      <span class="field-validation-valid" data-valmsg-for="Printed" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="PrintedDate">PrintedDate</label> 
     </div> 
     <div class="editor-field"> 
      <input class="datefield" id="PrintedDate" name="PrintedDate" type="date" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="PrintedDate" data-valmsg-replace="true"></span> 
     </div> 

     <div class="editor-label"> 
      <label for="AccreditationNo">AccreditationNo</label> 
     </div> 
     <div class="editor-field"> 
      <input class="text-box single-line" data-val="true" data-val-number="The field AccreditationNo must be a number." id="AccreditationNo" name="AccreditationNo" type="text" value="" /> 
      <span class="field-validation-valid" data-valmsg-for="AccreditationNo" data-valmsg-replace="true"></span> 
     </div> 
     </td></tr></table> 
     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
</form> 
+0

什么是神秘的类名? – elclanrs

+0

类名没有错。你能提供它输出的HTML而不是写HTML的脚本吗? – Popnoodles

+0

以及你如何显示其通行证? – Popnoodles

回答

0

你应该试试这个。

<script type="text/javascript"> 
$(document).ready(function() { 
$(".qno").keyUp(function(){ 
    $(".mk").val($(this).val()); 
}); 
}); 
</script> 
+0

我测试过这段代码,但它不工作。 –