tags:

views:

170

answers:

2

My script:

<script language="JavaScript">
function submitform()
{
  document.playsong.submit();
}
</script>

Submits the below form:

<form name="playsong" method="post" action="submit.php">
<input type="hidden" name="play" value="2009-05-19-3934.data">
<A href="javascript: submitform()">Play 1</A>
</form>

How can I change this so that I can have a series of links: <A href="javascript: submitform()">Play 1</A> That will submit the correct form without having to build a function to submit each form.

That is how can I make the function submit different various forms on the page dependent the link clicked.

+1  A: 

Consider:-

 function submitForm(form)
 {
      document[form].submit();
 }

 <a href="javascript:submitform('playsong')">Play 1</a>
AnthonyWJones
Perfect. Thanks!
ian
A: 

Build several links like

<form action="act1">
    <a href="#" onclick="goForm(this.parentNode); return false;">Play 1</a>
</form>
<form action="act2">
    <a href="#" onclick="goForm(this.parentNode); return false;">Play 2</a>
</form>
<form action="act3">
    <a href="#" onclick="goForm(this.parentNode); return false;">Play 3</a>
</form>
<form action="act4">
    <a href="#" onclick="goForm(this.parentNode); return false;">Play 4</a>
</form>
<form action="act5">
    <a href="#" onclick="goForm(this.parentNode); return false;">Play 5</a>
</form>

And make a js:

function goForm(frm) {
    if (frm != null)
        frm.submit();
}

There you go! =´p

José Leal
Anchor Element nodes do not have a form property - only form controls do.
David Dorward
Hmm, you are right, will fix
José Leal