-1

My form has two buttons: delete and play. Currently, the user must use the submit buttons at the bottom of the form to perform either of these tasks. I'd like to add a hyperlink to the top of the page with an onclick function that fires the appropriate submit button.

Here's what I'm working with. Currently, the hyperlink isn't working at all.

Hyperlink at top of page:

<a href='#' onlick='document.getElementById('playlist').click()'>test</a>

And here is my form with its submit buttons.

<form id = 'allverses' name= 'allverses' action='' method='POST'>
<button name="delete" type="SUBMIT" class="deletebutton" id="delete" value="delete" action="POST">
<button name="playlist" type="SUBMIT" class="playbutton" id="playlist" value="play" action="POST">
</form>
Dakota Lynch
  • 169
  • 2
  • 11
  • 1
    Your main mistake that I can see is that you used the same quote for both the tag and the string inside the tag. Try alternating, put `playlist` around double quotes or an escaped quote `\'` – Phiter Mar 26 '18 at 18:23
  • 6
    You have a typo: your link has `onlick` instead of `onclick`. – fennel Mar 26 '18 at 18:24
  • Use a tool that could correct your syntax. Visual Studio Code would be fine – CREM Mar 26 '18 at 18:25
  • You need first of all stick to a convention for your syntax and these errors will not occur – CREM Mar 26 '18 at 18:28

1 Answers1

0

Syntax Errors:

  1. onlick should be onclick.
  2. buttons end tag were not properly setup.

With correct syntax the following code works fine.

<a href='#' onclick="document.getElementById('playlist').click();">test</a>

<form id='allverses' name='allverses' action='' method='POST'>
<button name="delete" type="SUBMIT" class="deletebutton" id="delete" value="delete" action="POST" />
<button name="playlist" type="SUBMIT" class="playbutton" id="playlist" value="play" action="POST" />
</form>
Ghazni
  • 826
  • 8
  • 16
  • 1
    This appears to be a copy/paste of the code from the question. Why did you post it as an answer? – Quentin Mar 26 '18 at 18:35
  • there were some syntax errors, that i corrected and its now working fine. – Ghazni Mar 26 '18 at 18:36
  • 1
    Perhaps you could *explain the problem* instead of expressing your answer in the form of a game of spot-the-difference. (And if the problem was caused by a typo then it should be closed as off-topic and not answered anyway). – Quentin Mar 26 '18 at 18:37
  • Thanks! That seems to have done the trick. – Dakota Lynch Mar 26 '18 at 18:38
  • @Quentin now fine ? – Ghazni Mar 26 '18 at 18:39
  • 1
    In HTML it is allowed to put a `/` and the end of a boolean element (it is utterly pointless, but it stops the code being invalid for people who got into the habit when writing XHTML). The ` – Quentin Mar 26 '18 at 18:40