views:

3066

answers:

3

I have a form action that needs to have its value set from a variable. I need to set the variable once and it will be reflected many times throughout the DOM.

So:

variable = "somthing.html"; ...

+2  A: 

You can then change the form action to be equal to the variable name. Something like the following.

var variableName = "myform.htm";

this.form.action = variableName;

Edit, you can also do this with other elements, just like you would with any other piece of javascript, using things such as "getElementById()" to get the items from the DOM

Mitchel Sellers
A: 

i am not sure if this is what you are asking, but you could change the action of the document with this:

document.formname.action = "something.html";

Victor
+1  A: 

This will cause all FORMs to get the variable action:

<script src="jquery-1.2.6.pack.js"></script>
<script>
$(document).ready(function() {
    var variable = "something.html";
    $('form').attr("action", variable);
});
</script>
Scott Evernden