Marital Status Selection For HTML, JavaScript, PHP Array
Marital Status Selection For HTML JavaScript and PHP. Here, you can choose from a variety of marital status options using a dropdown menu. We provide examples of how to implement these options in both JavaScript and PHP. Whether you are building a form or integrating marital status into your application, you will find the relevant code snippets to help you get started.
Create Custom Marital Status for Your Needs
Customize your preferred marital status by selecting options from the provided table. You can then include these selected size in the dropdown menu, JavaScript array, or PHP array. The codes for the selected marital status will be displayed below.
Multilingual Options. Translated versions of the marital status selection list are available in various languages
# | Marital Status | Select |
---|---|---|
1 | Single | |
2 | Married | |
3 | Divorced | |
4 | Widowed | |
5 | Separated | |
6 | Domestic Partnership | |
7 | Civil Union | |
8 | Registered Partnership | |
9 | Unmarried Partner | |
10 | Engaged | |
11 | In a Relationship | |
12 | Open Relationship | |
13 | Long Distance | |
14 | Cohabiting | |
15 | Other |
HTML Drop Down
Here is the HTML code for creating a dropdown menu to select marital status
<select id="marital-status" name="marital-status" aria-label="Marital Status">
<option value="" disabled selected>Please select</option>
<option value="single">Single</option>
<option value="married">Married</option>
<option value="divorced">Divorced</option>
<option value="widowed">Widowed</option>
<option value="separated">Separated</option>
<option value="domestic-partnership">Domestic Partnership</option>
<option value="civil-union">Civil Union</option>
<option value="registered-partnership">Registered Partnership</option>
<option value="unmarried-partner">Unmarried Partner</option>
<option value="engaged">Engaged</option>
<option value="in-a-relationship">In a Relationship</option>
<option value="open-relationship">Open Relationship</option>
<option value="long-distance">Long Distance</option>
<option value="cohabiting">Cohabiting</option>
<option value="other">Other</option>
</select>
JavaScript Array
JavaScript Array of marital status
Here is the JavaScript array containing the marital status options
const maritalStatusOptions = [
"Single",
"Married",
"Divorced",
"Widowed",
"Separated",
"Domestic Partnership",
"Civil Union",
"Registered Partnership",
"Unmarried Partner",
"Engaged",
"In a Relationship",
"Open Relationship",
"Long Distance",
"Cohabiting",
"Other"
];
Usage Example
Use this array to create dynamic dropdown menu
const maritaStatusSelect = document.getElementById("marital-status");
// Populate dropdown
maritalStatusOptions.forEach(option => {
const optionElement = document.createElement("option");
optionElement.value = option.toLowerCase().replace(/\s+/g, '-');
optionElement.textContent = option;
maritaStatusSelect.appendChild(optionElement);
});
Try it your self Real Time Preview
PHP Array
PHP Array of marital status
Here is the PHP array containing the marital status options
<?php
$maritalStatusOptions = [
"Single",
"Married",
"Divorced",
"Widowed",
"Separated",
"Domestic Partnership",
"Civil Union",
"Registered Partnership",
"Unmarried Partner",
"Engaged",
"In a Relationship",
"Open Relationship",
"Long Distance",
"Cohabiting",
"Other"
];
?>
Usage Example PHP Array
Here is a quick example of how you might use this array to generate an HTML select option
<?php
$selectOption = '';
// create dropdown
foreach ($maritalStatusOptions as $option) {
$value = strtolower(str_replace(' ', '-', $option));
$text = htmlspecialchars($option);
$selectOption .= '<option value="' . $value . '">' . $text . '</option>'.PHP_EOL;
}
?>
<select id="marital-status">
<?php echo $selectOption ?>
</select>
Use Cases
User Profile Forms
Customer Surveys
Health and Wellness Applications
Financial Services
Online Dating Platforms
Social Media Profiles
Employment and HR Systems
Other drop down list