I wrote the following code:
out.println("<form action="PageA" method="post">");
// Table with input fields
out.println("<div id='split'>");
out.println("<input type="submit" value="Go" /> </form>");
out.println("<a href="Page B"><button>Back</button></a>");
out.println("</div>");
and now I wanted to format the 2 buttons right next to each other not one below the other one. So all I done: I created the div and in css said display flex.
But doing it like this, the buttons are next to each other, but as soon as I press the Back-Button I get redirected to PageA instead of PageB.
If I change the code to this:
out.println("<form action="PageA" method="post">");
// Table with input fields
out.println("<div id='split'>");
out.println("<input type="submit" id='bill_one1_create' value="Go" /> </form>");
out.println("</div>");
out.println("<a href="Page B"><button>Back</button></a>");
The Back button works as intended, but the buttons are not next to each other because the back-button is not in the div. What is the solution to this, to achieve both things?
I am using a Servlet so thats why i am using "out.println…"
2
Answers
Because you’re mixing up the HTML elements here:
When you click on "Back", are you pressing a button or clicking a link? How can you unambiguously determine the difference? According to the behavior described, you’re pressing the button and therefore submitting the form.
Don’t put a
<button>
inside of an<a>
(nor the other way around). It’s one or the other. If you want this element to be a link, just make it a link:Hello NEOPHYLE I see what you are saying. try this see
out.println("<div id='split'>"); out.println("<div><input type="submit" value="Go" /> </form></div>"); out.println("<div><a href="Page B"><button>Back</button></a></div>"); out.println("</div>");
then you go to the CSS file by calling the split ID and doing a flex display now playing with the margin and padding.
let me know if it’s good.