1

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.

4
  • Just use input type="submit" instead. Links should be links and inputs should be inputs. (And users should have to have JS on to submit a form). If you really want to have something that looks like a link submit a form - then use CSS to style the input. For that matter, it doesn't look like anything substantive us happening on the server anyway, so change from post to get and <a href="submit.php?play=2009-05-19-3934.data"> Commented May 20, 2009 at 11:08
  • @David: "Links should be links and inputs should be inputs", where do these rules come from and who is benefited by them? Commented May 20, 2009 at 11:19
  • @Anthony: From the land of non mixed race marriages probably. Commented May 20, 2009 at 13:31
  • @AnthonyWJones en.wikipedia.org/wiki/Affordances icant.co.uk/articles/pragmatic-progressive-enhancement cs.tut.fi/~jkorpela/www/links.html Commented May 20, 2009 at 13:53

2 Answers 2

2

Consider:-

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

 <a href="javascript:submitform('playsong')">Play 1</a>
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Anchor Element nodes do not have a form property - only form controls do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.