two inline buttons aligned in struts

Although it may seem simple, I am struggling to figure out how to align two buttons next to each other with different functions. One button is for logging in the user and the other is for signing up a new user. They are currently in two separate forms. Is there any way to align the log in button next to the sign-up button without using JavaScript or any other method – ideally just using JSP?

Here is my code for the login JSP file. Can these buttons be aligned without additional scripts? I would like to achieve this alignment solely through JSP.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login</title>
</head>
<body>

<s:form action="login">
    <s:textfield label="email" key="email" name="email" size="20" />
    <s:password label="password" key="password" size="20" />
    <s:submit value="LogIn"/>     
</s:form>

<s:form action="register.jsp">
    <s:submit value="SignUp" type="submit" float="right"/>     
</s:form>

EDIT

Updated code based on comments:

<s:form action="login" style="float:right"> 
  <s:textfield label="email" key="email" name="email" /> 
  <s:password label="password" key="password" /> 
  <s:submit value="LogIn"/> 
</s:form> 

<s:form action="register.jsp" style="float:right"> 
  <s:submit value="SignUp" type="submit"/> 
</s:form>

UPDATE: How can I make it look similar to this image provided by the user? ![enter image description here][2]

Answer №1

1) You don't need two separate forms, instead you can utilize s:submit and specify the action property within it.

2) If you want to display two buttons on the same line, you can make use of s:form's theme property

<s:form action="loginAction" theme="simple">
  <s:textfield label="email" key="email" name="email" size="20" /><br/>
  <s:password label="password" key="password" size="20" /><br/>
  <s:submit value="Register" name="registerBtn" />
  <s:submit value="LogIn" name="loginBtn"/>      
</s:form>

Update

loginAction

String registerBtn = request.getParameter("registerBtn");
String loginBtn = request.getParameter("loginBtn");

//if registerBtn is clicked then it's value Register is get stored in registerBtn.
//if not registerBtn is not clicked then variable registerBtn has null.
if(registerBtn != null)
{
  //return and call action for register.jsp
}
if(loginBtn != null)
{
  //do the login code here
}

To access the request object, you must implement the ServletRequestAware interface and override the setServletRequest method

public class LoginAction  implements ServletRequestAware
{
   HttpServletRequest request;
   public void setServletRequest(HttpServletRequest arg0) 
   {
      this.request = arg0;      
   }

   //rest of the above updated code here
} 

Answer №2

Change the positioning of the Signup button by removing float and applying it to the form field instead for it to function correctly.... check out a basic demo here

Furthermore, make sure to add the float properties to both form fields and not just one....

UPDATE

This tip will help you save your time

<form action="login" style="float:right;"> 
    <input type="textfield" label="email" key="email" name="email" /> <br />
  <input type="password" label="password" key="password" /> <br />
  <input type="submit" value="LogIn" style="float:right;"/> <br />
<form> 

<!--form method="post" ACTION="pagination.jsp"> 
<input type="submit" value="View"> 
</form--> 
<form action="register.jsp"> 
<input type="submit" value="SignUp" type="submit" style="float:right;margin-top:-20px;"/> 
<form>

see demo here

Answer №3

Although not the ideal solution, I managed to find a workaround for my problem that looks nice and functions adequately. I customized the buttons with CSS to enhance their appearance.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="java.util.*" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login</title>
</head>
<body>
<s:form action="login">
    <s:textfield label="email" key="email" name="email" size="20" />
    <s:password label="password" key="password" size="20" />
    <s:submit value="LogIn" style="float:left;"/>     
</s:form>
<s:form action="register.jsp">
    <s:submit value="SignUp" type="submit" style="float:right;margin-top:-5px;"/>     
</s:form>
</body>
</html>

Answer №4

Discover how to resolve the issue by using a div tag for one element and a td and div combination enclosed in another td within a tr that is functioning correctly

<tr>
                <td class="pageHeader">
                <div class="formButton"><input type="submit" value="Login" name="loginActionForm.loginButton" class="btncolor"/>
</div>
                    <td>
<div class="formButton"><input type="reset" name="loginActionForm.clearButton" value="Clear" class="btncolor" onfocus="document.forms[0].user.focus()"/>
</div></td>
                    </td>

        </tr>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting problem related to handling several Volley requests simultaneously

There seems to be an issue with my Volley request in response to user input - I have to press the button twice instead of just once to receive the desired response. Even after trying to use the wait() function, the problem persists and my application beco ...

Show the Array List in a left-to-right format

Is there a way to display an array list from left to right with a div scroll, instead of top to bottom? I am having trouble achieving this. Here is my demo code for reference. HTML <div> <h2 class="ylet-primary-500 alignleft">Sessions</h ...

Implementing dynamic background images in Angular 4 using div placeholders

Is there a way to include a placeholder or default image while waiting for item.imgSrc to load on the screen? <div class="style" *ngFor="let item of array; <div [style.backgroundImage]="url('+ item.imgSrc +')" class="image">< ...

Is there a way to submit the value of a textbox that has been generated dynamically using jQuery?

I am currently using the CodeIgniter framework and am attempting to incorporate textboxes in an HTML form. When the user clicks a button, a new textbox should be generated automatically using jQuery. However, when I submit the form, the values of the dynam ...

Show and hide the div by clicking a button

Looking at the image below, my goal is to display the div under the reply button. (The div consists of a text box and send button) https://i.stack.imgur.com/jnaV4.png The code I have currently functions correctly. However, when clicking any reply button ...

Whenever isEmailVerified() returns false, even after the email has been verified

When a user logs into their account, the system checks if they have verified their email address. If not, the EmailVerificationActivity is initiated. Upon clicking the SEND VERIFICATION EMAIL Button, a verification code is sent to the user's email add ...

Learn how to center content and stretch a column using Vuetify frameworks

Looking for a layout with 2 columns of equal height and centered content vertically? Here's how to achieve it using Vuetify! Check out the code snippet below: <div id="app"> <v-app> <v-row align="center"> ...

The functionality of HTML5 canvas image objects is not functioning as expected

I have been working on a function to retrieve an image object using HTML5 canvas, but I keep encountering an error alert (onerror event) function FetchImage() { var img = new Image(); img.src = "http://localhost/assets/images/loadedsprite.png"; ...

Retrieving a value from an input field within a table cell using jQuery

Looking for some help with a complex HTML Table structure like this one. <table id="items"> <tr class="total_up"> <td colspan="2" class="blank"></td> <td colspan="2" class="total-line">Total</td> ...

Tips for creating stylish diagonal backgrounds using Bootstrap 5

Is there a way to achieve diagonal styled backgrounds, like the examples shown below, while using Bootstrap 5 and (s)css? It would be ideal if this could be seamlessly integrated with other Bootstrap background utilities as outlined in the documentation h ...

Extract the text content from an HTML file while ignoring the tags to get the substring

Hello, I am a newcomer to the world of Web Development. I have an HTML document that serves as my resume, formatted in HTML. For example: html <p>Mobile: 12345678891 E-mail: <a href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Please retain only the clean <p> elements using Jsoup and remove all other content

I'm struggling to figure out a simple solution for this problem. My elements consist of a mix of <p>, p class="example">, and <p><strong>...</strong></p>. All I want to do is preserve everything within the clean < ...

The value of the HTML input control vanishes once padding is added

I am in need of some assistance with CSS in formatting the text box for BID VALUE (input element) (See in Image 1) Image 1 https://i.sstatic.net/4fQk8.jpg The product link can be found here When I try to widen the text box using padding, the text value in ...

The collision between the Textfield Label and Value is being caused by Chrome's Autofill feature

When using React, I noticed that Autocomplete Chrome values don't trigger the onChange event right away. This leads to an issue where there is a collision between the MUI TextField Label and the actual values during the initial page load. How can I go ...

Having Difficulty Applying a Background Color to a Class in Bulk

I am working on a unique HTML canvas for pixel art, which is created using a table made up of various divs all sharing the "pixel" class. I want to add a clear button that can reset the entire canvas, but changing the background color of each individual di ...

What are some ways to utilize the <span> tag to apply distinct styles to specific characters within text compared to

Imagine I have a string like <p>hi my name is john</p>. I know that I can use the span element to target specific characters and apply different styles using CSS. But what if I want to style "name" and "john" differently from each other and the ...

Disabling the submit button prevents the form from being submitted

After coming across this code designed to prevent double submission of a form, I noticed that it is not functioning correctly. Despite disabling the submit button and changing its value to "Please wait", the form is still being submitted. <input type=" ...

An error occurred: TypeError - Unable to access the 'value' property of a null object during a value change

Example ImageCreating a dynamic form where rows and select box options are added dynamically using 'x' and 'i' increment values in two JavaScript functions. The code works fine when the option selected is 0.5, but throws an error Uncaug ...

Using Java to print an already existing PDF document with correct scaling

Is there a way to print an existing PDF file without losing quality and scaling? I've already tried using PDFBox, but I'm having trouble with the scaling. The java pdfbox printerjob is not giving me the desired results. Using Scaling.SHRINK_TO_ ...

creating unique styles for your Ionic app with Angular using JSON

Having trouble changing the item color. Does anyone know why my CSS isn't working, or if I'm missing something? <ion-view title="Add order to a table"> <ion-content class="has-header has-subheader"> <ion-list> ...