0

There is a form that i want to submit and url rewrite at the same time. I can change url by adding onsubmit="rewrite_form(event);" option in form :

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;
}

Url changes but other values of form not posted to url generated page.

mdml
  • 22,442
  • 8
  • 58
  • 66
Burhan
  • 263
  • 4
  • 9

2 Answers2

0

Just change the form's action property instead.

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
}
plalx
  • 42,889
  • 6
  • 74
  • 90
  • i change form.action but not working is there any error in my script: function rewrite_form(e) { var form = document.getElementById("form1"); window.location = '/travel/search/' + form.from.value + '_to_' + form.to.value + '.html/'; var u = '/travel/search/' + form.from.value + '_to_' + form.to.value + '.html/'; form.action = window.location.u; if (e && e.preventDefault) { e.preventDefault(); } return false; } – Burhan Nov 04 '13 at 05:59
0

i got the solution:

    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();
}
Burhan
  • 263
  • 4
  • 9
  • Yeah, that's exactly the solution I gave you... changing the form's action. Now if you had errors in the rest of your code you should have specified it. – plalx Nov 04 '13 at 13:26