我想提交一个表单并同时重写url。我可以通过在表单中添加onsubmit="rewrite_form(event);"
选项来更改网址:
function rewrite_form(e) {
var form = document.forms[0]; // .getElementById("form1");
window.location = '/search/' + form.f.value + '_' + form.t.value + '.htm/' + form.amt_from.value;
if (e && e.preventDefault) { e.preventDefault(); }
return false;
}
网址更改但其他形式的值未发布到网址生成页面。
答案 0 :(得分:0)
只需改变表单的动作属性即可。
function rewrite_form(e) {
var form = documen.forms[0];
form.action = 'newurl';
//rest of code, make sure not to call e.preventDefault(); or return false
//because the form will not get submitted
}
答案 1 :(得分:0)
我得到了解决方案:
function rewrite_form() {
//Create custom link here
----------------------------
----------------------------------
//create form submit action
var url = '/search/' +'your custom link';
document.getElementById('FormId').action = url;
document.FormId.submit();
}
答案 2 :(得分:0)
我会这么认为:
console.log("form:",form,"f:",f.value,"t:",t.value,"amt_from",amt_from.value)
检查我的表格价值如果一切正确,请查看以下答案:Posting parameters to a url using the POST method without using a form