Print or echo javascript variable, not document, but be a value or part of a value for a DOM element, specifically for a form action

I have a form action that needs to have a value set from a variable. I need to set a variable once and it will appear many times in the DOM.

So:

variable = "somthing.html"; ...

0


source to share


3 answers


This will make all FORMs get the action of the variable:



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

      

+1


source


Then you can change the action of the form 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 as with any other javascript snippet, using things like "getElementById ()" to get the elements from the DOM

+3


source


I'm not sure if this is what you are asking for, but you can change the document action like this:

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

0


source







All Articles