HTML Submit value Property: Defining the Submit Button’s Text
The value property of an HTML submit button (<input type="submit">) defines the text that is displayed on the button. This text serves as a call to action for the user, prompting them to submit the form. Setting the value attribute is essential for creating user-friendly and intuitive forms.
Purpose of the value Property
The primary purpose of the value property is to:
- Set the visible text on the submit button, guiding the user on what action the button performs.
- Provide a clear and understandable label for the submit action.
- Customize the button text to match the form’s purpose and branding.
Syntax
The syntax for using the value property in an HTML submit button is straightforward:
<input type="submit" value="Submit Text">
Attributes
The value property is a string attribute that accepts any text. Hereβs a breakdown:
| Attribute | Type | Description |
|---|---|---|
| `value` | String | Specifies the text to be displayed on the submit button. If not specified, the default text depends on the browser’s default language (typically “Submit”). |
Examples
Let’s explore different ways to use the value property with HTML submit buttons. Each example will include the necessary HTML code to demonstrate the property’s functionality.
Basic Example
This example shows a basic submit button with the value property set to “Send”:
<form>
<label for="name">Name:</label><br />
<input type="text" id="name" name="name" /><br /><br />
<input type="submit" value="Send" />
</form>
The output will render a submit button displaying the text “Send.”
Customized Submit Button Text
Hereβs how to customize the submit button text to something more specific:
<form>
<label for="email">Email:</label><br />
<input type="email" id="email" name="email" /><br /><br />
<input type="submit" value="Subscribe Now" />
</form>
In this case, the submit button displays “Subscribe Now,” which is more descriptive for an email subscription form.
Submit Button in Different Languages
You can use the value property to display submit button text in different languages:
<form>
<label for="message">Message:</label><br />
<textarea id="message" name="message"></textarea><br /><br />
<input type="submit" value="Envoyer" />
</form>
Here, the submit button text is “Envoyer,” which is the French word for “Send.”
Dynamic Value Using JavaScript
Although the value attribute is typically set directly in HTML, you can also modify it dynamically using JavaScript:
<form id="myForm">
<label for="username">Username:</label><br />
<input type="text" id="username" name="username" /><br /><br />
<input type="submit" id="submitBtn" value="Submit" />
</form>
<script>
document.getElementById("submitBtn").value = "Register";
</script>
In this example, the initial value of the submit button is “Submit,” but JavaScript changes it to “Register” after the page loads.
Real-World Use Cases
The value property is used in many real-world scenarios:
- E-commerce: Displaying “Add to Cart” or “Checkout” on submit buttons.
- Contact Forms: Using “Send Message” or “Submit Inquiry” to clearly indicate the action.
- User Registration: Setting the value to “Create Account” or “Sign Up.”
- Surveys: Using “Submit Answers” or “Complete Survey.”
Example: Interactive Form with Dynamic Submit Button Text
Let’s create an interactive form that changes the submit button text based on user input.
<form id="dynamicForm">
<label for="task">Task:</label><br />
<input type="text" id="task" name="task" /><br /><br />
<input type="submit" id="dynamicSubmitBtn" value="Add Task" />
</form>
<script>
const taskInput_dyn = document.getElementById("task");
const submitBtn_dyn = document.getElementById("dynamicSubmitBtn");
taskInput_dyn.addEventListener("input", function () {
if (taskInput_dyn.value.trim() !== "") {
submitBtn_dyn.value = "Save Task";
} else {
submitBtn_dyn.value = "Add Task";
}
});
</script>
In this example, the submit button text changes from “Add Task” to “Save Task” when the task input field is not empty.
Form with Multiple Submit Buttons
In some cases, you might have multiple submit buttons in a form, each performing a different action. You can differentiate them using the value property:
<form>
<label for="comment">Comment:</label><br />
<textarea id="comment" name="comment"></textarea><br /><br />
<input type="submit" value="Post Comment" name="action" />
<input type="submit" value="Save as Draft" name="action" />
</form>
Here, there are two submit buttons: “Post Comment” and “Save as Draft.” The name attribute is also used to differentiate which button was clicked when the form is submitted.
Styling the Submit Button
You can style the submit button using CSS to match your website’s design:
<form>
<label for="feedback">Feedback:</label><br />
<textarea id="feedback" name="feedback"></textarea><br /><br />
<input type="submit" value="Submit Feedback" style="background-color: #4CAF50; color: white; padding: 10px 20px; border: none; cursor: pointer;" />
</form>
In this example, inline CSS is used to style the submit button with a green background, white text, and a pointer cursor.
Tips and Best Practices
- Clarity: Ensure the
valuetext clearly indicates the action performed by the submit button. - Consistency: Use consistent terminology across your forms for similar actions.
- Localization: Provide localized versions of the
valuetext for international users. - Accessibility: Ensure the button text is accessible to users with disabilities, following accessibility guidelines.
- CSS Styling: Use CSS to style the submit button to match your websiteβs design.
Conclusion
The value property of the HTML submit button is essential for providing clear and understandable labels for form submission actions. By customizing the button text, you can guide users, improve the user experience, and ensure that your forms are intuitive and effective. Whether you’re creating a simple contact form or a complex e-commerce checkout process, the value property is a key component of a well-designed form. π








