1

Beginner question: I would like to pass in window.location.hash to my form action parameter. How can I do this with a javascript call?

my current non-working code is:

<form method="POST"
    action="j_security_check"+window.location.hash>
sworded
  • 2,419
  • 4
  • 31
  • 48
  • use onload: http://www.w3schools.com/jsref/event_body_onload.asp – ControlAltDel Apr 23 '12 at 18:11
  • possible duplicate of [How to add/update an attribute to an HTML element using javascript?](http://stackoverflow.com/questions/710275/how-to-add-update-an-attribute-to-an-html-element-using-javascript) – Felix Kling Apr 23 '12 at 18:13

2 Answers2

3

Your javascript needs to be based on some kind of event. So you might want to do it when your submit button is pressed or something:

<form method="POST" action="">
<input type="submit" value="Submit" onclick="this.form.action = 'j_security_check'+window.location.hash" />

.....
Jage
  • 7,990
  • 3
  • 32
  • 31
0
<form name="hello" method="POST" action="">
    Hello
</form>​

<script>
    document.forms.hello.action = 'j_security_check'+window.location.hash;
    alert(document.forms.hello.action);
</script>

Proof: http://jsfiddle.net/2QE6h/1

iambriansreed
  • 21,935
  • 6
  • 63
  • 79