function submitform() { document.playsong.submit(); }

Submitting multiple forms with javascript

My script:

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

      

Gives the following 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 to have a series of links: < A href="javascript: submitform()">Play 1</A>

This will submit the correct form without having to create a function to submit each form.

This is how I can get the function to submit various different forms on the page depending on the click of the link.

+1


a source to share


2 answers


Consider: -



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

 <a href="javascript:submitform('playsong')">Play 1</a>

      

+2


a source


Create some 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 let's make js:



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

      

Go here! = 'p

0


a source







All Articles