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
1Single
2Married
3Divorced
4Widowed
5Separated
6Domestic Partnership
7Civil Union
8Registered Partnership
9Unmarried Partner
10Engaged
11In a Relationship
12Open Relationship
13Long Distance
14Cohabiting
15Other

HTML Drop Down

Here is the HTML code for creating a dropdown menu to select marital status

HTML
<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

JavaScript
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

HTML
<select id="marital-status">
  <option value="">Select marital status</option>
</select>
javaScripr
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
<?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
<?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