-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
40 lines (35 loc) · 1.02 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<form class="form">
<select name="select" id="mySelect">
<option default value="choice1">Choice One</option>
<option value="choice2">Choice Two</option>
</select>
<button type="submit">Submit</button>
</form>
<form class="form">
<select name="select" id="mySelect2">
<option default value="choice1">Choice One</option>
<option value="choice2">Choice Two</option>
</select>
<button type="submit">Submit</button>
</form>
<script>
let plans = {
mySelect: {
choice1: "https://mylink.com",
choice2: "https://myotherlink.com"
},
mySelect2: {
choice1: "https://my3rdlink.com",
choice2: "https://my4th.com"
}
}
//let select = document.querySelector("#mySelect")
let forms = Array.from(document.querySelectorAll(".form"))
forms.map(form =>
form.addEventListener("submit", event => {
event.preventDefault()
const formSelect = event.target.querySelector("select")
window.location.assign(plans[formSelect.id][formSelect.value])
})
)
</script>