使用ColdFusion基于DB记录集生成多个表单。
<div class="mrostatus"><form name="contact" method="post">
<input type="text" name="userName">
<input type="hidden" name="userFile" value="#FileName#.pdf" />
<input type="button" id="userSubmit" name="userSubmit" value="Change Document Password">
</form>
</div>
上述表单重复记录集中的每条记录。按“userSubmit”按钮时,每次只显示第一个记录的数据。我如何使这些独特?这是数据传递到的地方:
// JavaScript Document
$(document).ready(function(){
$("input[name='userSubmit']").click(function(){
//call a function to submit the form data
submitForm();
});
});
submitForm = function(){
var userPassword = $("input[name='userName']").val();
var userFile = $("input[name='userFile']").val();
//create a new instance of our proxy
var submission = new formData();
//set the handler to refresh the grid when the function has been run successfully
submission.setCallbackHandler(verifySubmission);
//set the error function in case the function does not run correctly
submission.setErrorHandler(errorHandler);
//call the method via the proxy
//submission.initSubmit(userPassword, userFile);
alert(userPassword +' '+ userFile);
}
我不清楚如何让JQuery了解每个表单都是独一无二的。任何帮助表示赞赏。 谢谢。 -CK
答案 0 :(得分:4)
$("input[name='userName']")
查找文档中名称attr设置为userName
的所有输入。.val()
方法仅作用于调用它的集合中的第一个元素。因此,您的提交函数每次运行时都会读取文档中第一个userName输入的值。您需要使其在单击的特定按钮的范围内运行,并在该按钮所在的表单内搜索。
submitForm = function(){
var $form = $( this ).closest( 'form' );
var userPassword = $form.find("input[name='userName']").val();
var userFile = $form.find("input[name='userFile']").val();
//create a new instance of our proxy
var submission = new formData();
//set the handler to refresh the grid when the function has been run successfully
submission.setCallbackHandler(verifySubmission);
//set the error function in case the function does not run correctly
submission.setErrorHandler(errorHandler);
//call the method via the proxy
//submission.initSubmit(userPassword, userFile);
alert(userPassword +' '+ userFile);
};
// JavaScript Document
$(document).ready(function(){
$("input[name='userSubmit']").click( submitForm );
});