Province data not getting submitted on click - html

I'm creating a sign up form as part of my assignment. The form data is getting submitted except for the province data. The provinces are in a dropdown list. I initially only had the value and thought that was the issue so I added the name and id but I'm still experiencing the same issue. What am I missing? I can't seem to figure it out. Below is my html code for the dropdown, checkboxes and radio button. I'm only using html.
<h3>Which province are you from?</h3>
<select>
<option value="easternCape" name="province" id="=ec">Eastern Cape</option>
<option value="freeState" name="province" id="fs">Free State</option>
<option value="gauteng" name="province" id="gp">Gauteng</option>
<option value="kwaZulu-Natal" name="province" id="kzn">KwaZulu-Natal</option>
<option value="limpopo" name="province" id="lim">Limpopo</option>
<option value="mpumalanga" name="province" id="mp">Mpumalanga</option>
<option value="northWest" name="province" id="nw">North West</option>
<option value="northernCape" name="province" id="nc">Northern Cape</option>
<option value="westernCape" name="province" id="wc">Western Cape</option>
</select><br>
<h3>Preferred payment method</h3>
<input type="checkbox" name="pmtMthd" value="eft">EFT<br>
<input type="checkbox" name="pmtMthd" value="cc">Credit Card<br>
<input type="checkbox" name="pmtMthd" value="ppal">Paypal<br>
<h3>Preferred delivery method</h3>
<input type="radio" name="method" value="courier">Courier<br>
<input type="radio" name="method" value="post">Post<br>

I believe the issue is that you are adding the ID and name to the options instead of the select tag itself.
<select name="province" id="province">
<option value="easternCape">Eastern Cape</option>
<option value="freeState">Free State</option>
<option value="gauteng">Gauteng</option>
<option value="kwaZulu-Natal">KwaZulu-Natal</option>
<option value="limpopo">Limpopo</option>
<option value="mpumalanga">Mpumalanga</option>
<option value="northWest">North West</option>
<option value="northernCape">Northern Cape</option>
<option value="westernCape">Western Cape</option>
</select>
When getting the form result, pull the value from the name and ID "province" and you should get the selected value. The select tag is a special "input" tag for a form, so you get the value from it instead of its options

Related

How to require a selection in my select element on my signup form [duplicate]

This question already has answers here:
How do I make a field required in HTML?
(16 answers)
Closed 2 months ago.
<label for="select-choice">Birthday:</label>
<select name="select-choice" id="select-choice">
<option value="0" selected disabled>Month</option>
<option value="january">Jan</option>
<option value="february">Feb</option>
<option value="march">Mar</option>
<select name="birthday-day" id="day">
<option value="0" selected disabled>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<select name="birthday-year" id="year">
<option value="0" selected disabled>Year</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
The Sign Up or Register page is okay but I could not validate the birthday, When I try filling it on a browser I expect it to demand or require birthday option, every other input option was demanding or requiring me to input an information but if I purposely did not fill the birthday and hit the submit button it will go through just like that, please how do I validate the birthday using HTML?
You just need to add "required" to each of your selects and then just add an empty value instead of a "0" value. When you press a button, it will detect it has no value and will automatically make the select required.
<form>
<label for="select-choice">Birthday:</label>
<select name="select-choice" id="select-choice" required>
<option value="">Month</option>
<option value="january">Jan</option>
<option value="february">Feb</option>
<option value="march">Mar</option>
</select>
<select name="birthday-day" required>
<option value="">Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="birthday-year" id="year" required>
<option value="">Year</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
<button>submit</button>
</form>

Need to fix Errors pointed out by HTML checker

<div class="needContent">
<label for="Country" >Country</label> //ERROR
<span class="red-star">∗</span>
<input list="browsers" name="Country" required="required">
<datalist id="browsers">
<option value="Canada">
<option value="The United States">
<option value="India">
<option value="JPakistan">
<option value="Germany">
</datalist>
</div>
Error: The for attribute of the label element must refer to a non-hidden form control.
From line 96, column 6; to line 96, column 27
nt">↩ Countr
<div class="needContent">
<label for="Province" >Province</label>
<span class="red-star">∗</span>
<select name="Province" id="Province" onkeyup="starShow()"
required="required">
<option value="">Alberta</option>
<option value="">British Columbia</option>
<option value="">Manitoba</option>
<option value="">New Brunswick</option>
<option value="">Newfoundland and Labrador</option>
<option value="">Nova Scotia</option>
<option value="">Ontario</option>
<option value="">Prince Edward Island</option>
<option value="">Quebec</option>
<option value="">Saskatchewan</option>
<option value="">Northwest Territories</option>
<option value="">Nunavut</option>
<option value="">Yukon</option>
</select>
</div>
So according to my assignment I am supposed to create
Dropdown list: select element with options - the 10 provinces and 3 territories of Canada, required. The full names of provinces and territories will be showed up on the list and organized in two groups: Provinces and Territories. The values for option elements must use standard 2-letter abbreviations.
but if I put the (value ="ON") it gives me errors in HTML checker. Can someone help me fix it please?

Chrome Credit Card Autofill Field Name Bug/Conflict

Does anyone know why a form field name would cause Chrome's autofill to stop working correctly? If you open the fiddle I've created in Chrome, you'll notice the Card Number field populates correctly, but not the expiry month and year. If you change the name of the BirthDate.MM select list to BirthDate.Foo and BirthDate.YYYY to BirthDate.Bar; and then and re-run, the credit card autofill works as expected. Now, an obvious suggestion would be to simply disable the bday- autofill and change the those values to "off" or completely remove the autocomplete attribute. Astoundingly, removing the autocomplete attribute or changing the bday- values to "off" on those fields then breaks the address autofill!!!
The solution to the autofill problem itself is simply change the field names. What I want to know is why? Can anyone clarify how I unwittingly poked Chrome's field name sniffing feature?
<fieldset>
<legend>Payment Information</legend>
<div><input autocomplete="cc-number" id="CreditCard_CardNumber" maxlength="16" name="CreditCard.CardNumber" pattern="\d*" required="" type="text" placeholder="Card Number" value="" /></div>
<div>
<label for="CreditCard_ExpirationMonth">Expires:</label>
<select autocomplete="cc-exp-month" id="cardExpirationMonth" name="CreditCard.ExpirationMonth" required="">
<option value="">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select autocomplete="cc-exp-year" id="cardExpirationYear" name="CreditCard.ExpirationYear" required="">
<option value="">Year</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
<option value="2029">2029</option>
<option value="2030">2030</option>
<option value="2031">2031</option>
<option value="2032">2032</option>
<option value="2033">2033</option>
<option value="2034">2034</option>
<option value="2035">2035</option>
<option value="2036">2036</option>
<option value="2037">2037</option>
</select>
</div>
</fieldset>
Use the lower-case version of your names.
For me , using Name as name attribute is not working, autofill recognizes the field as CC !!
If I change it to name , works like a charm.
Hope this helps!

Chrome caches select menu

I have a select menu.
Example:
<select autocomplete="off"> <option value="" selected="selected">Select Quantity</option>
<option value="6" autocomplete="off">6</option>
<option value="12" autocomplete="off">12</option>
<option value="18" autocomplete="off">18</option>
<option value="24" autocomplete="off">24</option>
</select>
If the user selects a value and then navigates to a different page and back...the browser caches the selected value (even though I have switched off caching in the cache related headers).
How can I prevent Chrome from caching these select values?
Add autocomplete="off" to the form (not the select element):
<form autocomplete="off">
<select> <option value="" selected="selected">Select Quantity</option>
<option value="6" autocomplete="off">6</option>
<option value="12" autocomplete="off">12</option>
<option value="18" autocomplete="off">18</option>
<option value="24" autocomplete="off">24</option>
</select>
</form>

Include hidden input with optgroup

Is it possible to to include multiple (or a single) <input type = hidden> nested within an <optgroup>'s <option>?
For example, I might have
<select>
<optgroup label="North America">
<option value="Canada">Canada</option>
<input type="hidden" name="capital" value="Ottawa">
<option value="United States">United States</option>
<input type="hidden" name="capital" value="Washington D.C.">
<option value="Mexico">Mexico</option>
<input type="hidden" name="capital" value="Mexico City">
</optgroup>
...
</select>
If I choose "Canada" could I get "Ottawa" and only "Ottawa" submitted also?
What you are asking for is not exactly possible, but it sounds like the result you want is...
<select name="capital">
<optgroup label="North America">
<option value="Ottawa">Canada</option>
<option value="Washington D.C.">United States</option>
<option value="Mexico City">Mexico</option>
</optgroup>
...
</select>
When the user selects "Canada" from the drop-down, the value "Ottawa" will be submitted to the server.