<!DOCTYPE html>
<html>
<head>
<title>Swap Select Boxes</title>
</head>
<body>
<select id="s1">
<option value="EN">EN</option>
<option value="DE" selected>DE</option>
<option value="RO">RO</option>
</select>
<select id="s2">
<option value="EN">EN</option>
<option value="DE">DE</option>
<option value="RO"selected>RO</option>
</select>
<input type="button" onclick="
var s1 = document.getElementById('s1');
var s2 = document.getElementById('s2');
var temp = s1.value; s1.value = s2.value; s2.value = temp;" value="Swap Values" />
</body>
</html>
Or with function:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 50%;
}
button:hover {
opacity: 0.8;
}
select {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
</style>
<title>Swap Select Boxes with JS</title>
<script type="text/javascript">
function swap() {
var s1 = document.getElementById('s1');
var s2 = document.getElementById('s2');
var tmp = s1.value;
s1.value = s2.value;
s2.value = tmp;
}
</script>
</head>
<body>
<select id="s1">
<option value="EN">EN</option>
<option value="DE" selected>DE</option>
<option value="RO">RO</option>
</select>
<select id="s2">
<option value="EN">EN</option>
<option value="DE">DE</option>
<option value="RO"selected>RO</option>
</select>
<button onclick="swap()">Swap Languages</button>
</body>
</html>