这可能看起来很奇怪,但我希望能够使用通过get-param列表传入的值填充静态Web表单。
假设我有一个页面'self.html':
<form action="self.html" method="get" accept-charset="utf-8">
<label for = "40">New Question?</label>
<input type="radio" name="40" id="40" value="Yes"> Yes
<input type="radio" name="40" id="40" value="No"> No
<label for = "41">What's your favourite colour?</label>
<input type="text" name="43" value="" id="41">
</form>
每当输入更改时,我需要提交表单:
$(document).ready(function(){
$('input').change(function(){
$("form:first").submit();
});
// collate_results();
});
但很明显,我想保留这些值,以便在重新加载时不会重置它们。
(为什么?因为我是在一个FileMaker Web视图中完成的,从表单中提取数据的唯一方法是获取源代码(url)并解析它…因此,我需要url来更新以反映表单的当前状态,并且能够为我想要显示的任何新记录传入数据…)
更新:
这是我的非工作代码-它是很好的单值字段,但对于单选按钮失败…
$('input').change(function(){
$("form:first").submit();
});
var qString = jQuery.url.attr("query");
if(qString) {
qString = qString.split("&");
$(qString).each( function() {
var parts = this.split("=");
var item = $('#'+parts[0]);
if($(item).attr('type') == 'text') {
$('#'+parts[0]).val(parts[1]);
};
if($(item).attr('type') == 'radio') {
$(item).each(function() {
console.log(this);
if($(this).val() == parts[1]) {
$(this).attr('checked','checked');
} else {
$(this).attr('checked','');
}
});
};
})
}
});
问题是我
将
表单上有多个值为yes、no和na的单选按钮,因此jquery想要这样做的方式似乎不适用。如果这有帮助的话,我可以重新识别收音机按钮…
<form action="self.html" method="get" accept-charset="utf-8">
<label for = "40">New Question?</label>
<input type="radio" name="47" id="47_yes" value="Yes">Yes
<input type="radio" name="47" id="47_no" value="No" checked> No
<label for = "48">What's your favourite colour?</label>
<input type="text" name="48" value="" id="48">
</form>