Ok, so this is a bit confusing to explain but basically, I am creating a checkout page which users can either choose "delivery" or "Pickup", once chosen it 'unhides' the corresponding form which once filled out will send data to the next page. The problem is that I want to use the same id's for both forms but just add an address to the delivery one but it seems like it will only take data from the first/top form which is the takeaway-
function Delivery1() {
var x = document.getElementById("Pickup");
var y = document.getElementById("Delivery");
var w = document.getElementById("btn1");
var z = document.getElementById("btn2");
if (y.style.display === "none") {
x.style.display = "none";
y.style.display = "block";
w.style.backgroundColor = "#b20c0c";
z.style.backgroundColor = "#cc1400";
} else {
y.style.display = "none";
}
}
function Pickup1() {
var y = document.getElementById("Delivery");
var x = document.getElementById("Pickup");
var w = document.getElementById("btn1");
var z = document.getElementById("btn2");
if (x.style.display === "none") {
x.style.display = "block";
y.style.display = "none";
z.style.backgroundColor = "#b20c0c";
w.style.backgroundColor = "#cc1400";
} else {
z.style.backgroundColor = "#cc1400";
x.style.display = "none";
}
}
<center>
<button id="btn1" onclick="Delivery1()" class="btn" style="height:90px; width: 180px">Delivery</button>
<button id="btn2" onclick="Pickup1()" class="btn" style="height:90px; width: 180px">Pickup</button>
</center>
<div id="Pickup" style="display: none;">
<form action="order.html" method="post" id="checkout-order-form">
<fieldset id="fieldset-billing">
<legend>Pickup</legend>
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name" data-type="string" data-message="This field cannot be empty" />
</div>
<div>
<label for="email">Phone Number</label>
<input type="text" name="email" id="email" data-type="expression" data-message="Not a valid phone address" />
</div>
<div>
<label for="country">Select Store</label>
<select name="country" id="country" data-type="string" data-message="This field cannot be empty">
<option value="">None</option>
<option value="Leopold">Leopold</option>
</select>
</fieldset>
<p><input type="submit" id="submit-order" value="Submit" class="btn" /></p>
</div>
</form>
<div id="Delivery" style="display: none;">
<form action="order.html" method="post" id="checkout-order-form">
<fieldset id="fieldset-shipping">
<legend>Delivery</legend>
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name" data-type="string" data-message="This field cannot be empty" />
</div>
<div>
<label for="email">Phone Number</label>
<input type="text" name="email" id="email" data-type="expression" data-message="Not a valid phone number" />
</div>
<div>
<label for="address">Address</label>
<h3>(Must be in or in neighbouring suburbs of leopold no more than 10km)</h3>
<input type="text" name="address" id="address" data-type="string" data-message="This field cannot be empty" />
</div>
</fieldset>
<p><input type="submit" id="submit-order" value="Submit" class="btn" /></p>
</div>
</form>
</div>
</div>
<footer id="site-info">
Copyright © Fu Chinese
</footer>
If its needed i can post the javascript form but its quite long. If anyone can help me with a solution or easier way to do this that would be great. Thanks :)