0

I am having trouble wrapping my head around getting Perl to work with HTML. I am trying to do something I think is simple, but I cant find anything like it online.

Let's say I have a blank web page that has only a button labeled new, and when I press it, I want to destroy the button and create two new buttons, one that is a submit button, and one cancel that creates the old new button.

How would I go about doing that, without reloading the page?

From my understanding, the original HTML code would look something like this.

<form action="/cgi-bin/switchButtons.cgi" method="POST">
<input type="button" value="new">
</form>

and afterward should look like this.

    <form action="/cgi-bin/switchButtons.cgi" method="POST">
    <input type="submit" value="submit">
    <input type="button" value="cancel">
    </form>

On pressing cancel, it should refer back to the first snippet.

2
  • 4
    without reloading the page means you'll want to use JavaScript on the front end, not Perl on the back end Commented May 5, 2017 at 17:53
  • @cajwine: Much as I am fond of Perl and dislike JavaScript, I have to acknowledge that the latter is far better suited to DOM manipulation than Perl. Commented May 5, 2017 at 21:13

1 Answer 1

3

You can't do that.

/cgi-bin/switchButtons.cgi is a Perl program on the server. Clicking on one of the form's buttons sends a request message to the server, which runs switchButtons.cgi. The output from that program is the contents of a new web page which is sent back to the client (the browser). Of course that involves loading a new page

You could do it in JavaScript, which is part of the page and runs on the client. You can specify that a button will cause the browser to execute some JavaScript, which could alter the page 9n any way you want. But that doesn't answer your question

Sign up to request clarification or add additional context in comments.

Comments

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.