Alex Rivera | Logout

How to use JavaScript to change the form action

Asked 2011-03-19T11:24:00.150
50

My current code is as follows:

<div class="fr_search">   
  <form action="/"  accept-charset="UTF-8" method="post" id="search-theme-form">
  .......
  </form>
</div>

Now I want to write a function to change the form action and method, when a condition is met. How do I write this code?

For example,

function test() {
   if (selectedIndex === 1)....
} // How do I write this code?
Edit
Report

1 Answer

34

Try this:

var frm = document.getElementById('search-theme-form') || null;
if(frm) {
   frm.action = 'whatever_you_need.ext' 
}
answered 2011-03-19T11:28:22.923

Your Answer