if statement javascript on select tag - javascript

I'm new to writing JavaScript
I want to write something like this but I cant access the opt group in my JavaScript …
if (select-country value == an option in optgroup(africa) ){
countryGrade=50
}
else if(select-country value == an option in optgroup(north america) ){
countryGrade=20
}
else if(select-country value == an option in optgroup(south america) ){
countryGrade=30
}
it is a form so when the form is submitted it will go over the conditions
what i to do is assign points to the country grade that is why im using if statement
var scholarshipGrade=document.getElementById("scholar_grade")
var form=document.getElementById("form")
var age=document.getElementById("age")
var fname=document.getElementById("fname")
var mname=document.getElementById("mname")
var lname=document.getElementById("name")
var ageGrade=0
var countryGrade=0
var subjectGrade=0;
scholarshipGrade=ageGrade+countryGrade+subjectGrade
form.addEventListener('submit',function(e){
e.preventDefault()
if(age.value >=18 && age.value <=24){
ageGrade= 100
}
else if(age.value >=25 && age.value <=30){
ageGrade=80
}
else if(age.value >=31 && age.value <=35){
ageGrade=50
}
else if(age.value >=36 && age.value <=40){
ageGrade=30
}
else if(age.value >=41){
ageGrade=10
}
})
body{
background-color:gray;
}
h1{
text-align: center;
}
p{
text-align: center;
}
input[type=text], select, textarea, input[type=email]{
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
<Html>
<head>
<link rel="stylesheet" href="style.css">
<title>
Scholarship Project
</title>
</head>
<body>
<h1>Apply For Scholarship</h1>
<div><p>You can apply for a scholarship here, check if you qualify after filling the following fields,after all fields are filled submit the form</p></div>
<form id="form" name="form">
<label> Firstname </label>
<input type="text" name="firstname" id="fname" /> <br> <br>
<label> Middlename: </label>
<input type="text" name="middlename" id="mname"/> <br> <br>
<label> Lastname: </label>
<input type="text" name="lastname" id="lname"/> <br> <br>
<br>
<label>
Gender :
</label>
<input type="radio" name="male"/> Male
<input type="radio" name="female"/> Female
<br>
<br>
<label>Enter your age: </label>
<input type="number" id= "age" name="num" min="18" max="60"><br> <br>
<label>
Phone :
</label>
<input type="text" name="phone" /> <br> <br>
Address
<br>
<textarea cols="80" rows="5" value="address">
</textarea>
<br> <br>
Email:
<input type="email" id="email" name="email"/> <br>
<br> <br>
<label for="country">select your country</label> <br>
<select id="select-country" name="country" >
<option value="" selected="">Select country</option>
<optgroup label="Africa" id="africa" >
<option value="DZ">Algeria</option>
<option value="AO">Angola</option>
<option value="BJ">Benin</option>
<option value="BW">Botswana</option>
<option value="BF">Burkina Faso</option>
<option value="BI">Burundi</option>
<option value="CM">Cameroon</option>
<option value="CV">Cape Verde</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="KM">Comoros</option>
<option value="CG">Congo</option>
<option value="CD">Congo, the Democratic Republic of the</option>
<option value="DJ">Dijibouti</option>
<option value="EG">Egypt</option>
<option value="GQ">Equatorial Guinea</option>
<option value="ER">Eritrea</option>
<option value="ET">Ethiopia</option>
<option value="GA">Gabon</option>
<option value="GM">Gambia</option>
<option value="GH">Ghana</option>
<option value="GN">Guinea</option>
<option value="GW">Guinea-Bissau</option>
<option value="CI">Cote d'Ivoire (Ivory Coast)</option>
<option value="KE">Kenya</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</option>
<option value="MG">Madagascar</option>
<option value="MW">Malawi</option>
<option value="ML">Mali</option>
<option value="MR">Mauritania</option>
<option value="MU">Mauritius</option>
<option value="YT">Mayotte</option>
<option value="MA">Morocco</option>
<option value="MZ">Mozambique</option>
<option value="NA">Namibia</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="RE">Reunion</option>
<option value="RW">Rwanda</option>
<option value="ST">Sao Tome and Principe</option>
<option value="SH">Saint Helena</option>
<option value="SN">Senegal</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SO">Somalia</option>
<option value="ZA">South Africa</option>
<option value="SS">South Sudan</option>
<option value="SD">Sudan</option>
<option value="SZ">Swaziland</option>
<option value="TZ">Tanzania</option>
<option value="TG">Togo</option>
<option value="TN">Tunisia</option>
<option value="UG">Uganda</option>
<option value="EH">Western Sahara</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</optgroup>
<optgroup data-points='20' label="North America" class="namerica">
<option value="US">United States</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="CA">Canada</option>
<option value="MX">Mexico</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AW">Aruba</option>
<option value="BS">Bahamas</option>
<option value="BB">Barbados</option>
<option value="BZ">Belize</option>
<option value="BM">Bermuda</option>
<option value="VG">British Virgin Islands</option>
<option value="KY">Cayman Islands</option>
<option value="CR">Costa Rica</option>
<option value="CU">Cuba</option>
<option value="DM">Dominica</option>
<option value="DO">Dominican Republic</option>
<option value="SV">El Salvador</option>
<option value="GD">Grenada</option>
<option value="GP">Guadeloupe</option>
<option value="GT">Guatemala</option>
<option value="HT">Haiti</option>
<option value="HN">Honduras</option>
<option value="JM">Jamaica</option>
<option value="MQ">Martinique</option>
<option value="MS">Montserrat</option>
<option value="AN">Netherlands Antilles</option>
<option value="NI">Nicaragua</option>
<option value="PA">Panama</option>
<option value="PR">Puerto Rico</option>
<option value="KN">Saint Kitts and Nevis</option>
<option value="LC">Saint Lucia</option>
<option value="VC">Saint Vincent and the Grenadines</option>
<option value="TT">Trinidad and Tobago</option>
<option value="TC">Turks and Caicos Islands</option>
<option value="VI">US Virgin Islands</option>
</optgroup>
<optgroup data-points='30' label="South America" class="samerica">
<option value="AR">Argentina</option>
<option value="BO">Bolivia</option>
<option value="BR">Brazil</option>
<option value="CL">Chile</option>
<option value="CO">Colombia</option>
<option value="EC">Ecuador</option>
<option value="FK">Falkland Islands (Malvinas)</option>
<option value="GF">French Guiana</option>
<option value="GY">Guyana</option>
<option value="PY">Paraguay</option>
<option value="PE">Peru</option>
<option value="SR">Suriname</option>
<option value="UY">Uruguay</option>
<option value="VE">Venezuela</option>
</optgroup>
<optgroup data-points='40' label="Asia" class="asia">
<option value="AF">Afghanistan</option>
<option value="AM">Armenia</option>
<option value="AZ">Azerbaijan</option>
<option value="BH">Bahrain</option>
<option value="BD">Bangladesh</option>
<option value="BT">Bhutan</option>
<option value="IO">British Indian Ocean Territory</option>
<option value="BN">Brunei Darussalam</option>
<option value="KH">Cambodia</option>
<option value="CN">China</option>
<option value="CX">Christmas Island</option>
<option value="CC">Cocos (Keeling) Islands</option>
<option value="GE">Georgia</option>
<option value="HK">Hong Kong</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IR">Iran</option>
<option value="IQ">Iraq</option>
<option value="IL">Israel</option>
<option value="JP">Japan</option>
<option value="JO">Jordan</option>
<option value="KZ">Kazakhstan</option>
<option value="KP">Korea, Democratic People's Republic of</option>
<option value="KR">Korea, Republic of</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Lao</option>
<option value="LB">Lebanon</option>
<option value="MY">Malaysia</option>
<option value="MV">Maldives</option>
<option value="MN">Mongolia</option>
<option value="MM">Myanmar (Burma)</option>
<option value="NP">Nepal</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PH">Philippines</option>
<option value="QA">Qatar</option>
<option value="RU">Russian Federation</option>
<option value="SA">Saudi Arabia</option>
<option value="SG">Singapore</option>
<option value="LK">Sri Lanka</option>
<option value="SY">Syria</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TH">Thailand</option>
<option value="TP">East Timor</option>
<option value="TM">Turkmenistan</option>
<option value="AE">United Arab Emirates</option>
<option value="UZ">Uzbekistan</option>
<option value="VN">Vietnam</option>
<option value="YE">Yemen</option>
</optgroup>
<optgroup data-points='10' label="Rest Of The World" class="rotws">
<option value="GB">United Kingdom</option>
<option value="AQ">Antarctica</option>
<option value="AL">Albania</option>
<option value="AD">Andorra</option>
<option value="AT">Austria</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BA">Bosnia and Herzegovina</option>
<option value="BG">Bulgaria</option>
<option value="HR">Croatia (Hrvatska)</option>
<option value="CY">Cyprus</option>
<option value="CZ">Czech Republic</option>
<option value="FR">France</option>
<option value="GI">Gibraltar</option>
<option value="DE">Germany</option>
<option value="GR">Greece</option>
<option value="VA">Holy See (Vatican City State)</option>
<option value="HU">Hungary</option>
<option value="IT">Italy</option>
<option value="LI">Liechtenstein</option>
<option value="LU">Luxembourg</option>
<option value="MK">Macedonia</option>
<option value="MT">Malta</option>
<option value="MD">Moldova</option>
<option value="MC">Monaco</option>
<option value="ME">Montenegro</option>
<option value="NL">Netherlands</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="RO">Romania</option>
<option value="SM">San Marino</option>
<option value="RS">Serbia</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="ES">Spain</option>
<option value="UA">Ukraine</option>
<option value="DK">Denmark</option>
<option value="EE">Estonia</option>
<option value="FO">Faroe Islands</option>
<option value="FI">Finland</option>
<option value="GL">Greenland</option>
<option value="IS">Iceland</option>
<option value="IE">Ireland</option>
<option value="LV">Latvia</option>
<option value="LT">Lithuania</option>
<option value="NO">Norway</option>
<option value="SJ">Svalbard and Jan Mayen Islands</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="TR">Turkey</option>
<option value="AS">American Samoa</option>
<option value="AU">Australia</option>
<option value="CK">Cook Islands</option>
<option value="FJ">Fiji</option>
<option value="PF">French Polynesia (Tahiti)</option>
<option value="GU">Guam</option>
<option value="KB">Kiribati</option>
<option value="MH">Marshall Islands</option>
<option value="FM">Micronesia, Federated States of</option>
<option value="NR">Nauru</option>
<option value="NC">New Caledonia</option>
<option value="NZ">New Zealand</option>
<option value="NU">Niue</option>
<option value="MP">Northern Mariana Islands</option>
<option value="PW">Palau</option>
<option value="PG">Papua New Guinea</option>
<option value="PN">Pitcairn</option>
<option value="WS">Samoa</option>
<option value="SB">Solomon Islands</option>
<option value="TK">Tokelau</option>
<option value="TO">Tonga</option>
<option value="TV">Tuvalu</option>
<option value="VU">Vanuatu</option>
<option valud="WF">Wallis and Futuna Islands</option>
</optgroup>
</select><br><br>
<label for="subjects"></label>
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name ="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<button type="submit">submit</button>
</form>
<div>
<p></p>
<p id="scholar_grade"></p>
</div>
<script src="script.js"></script>
</body>
</html>

To find the associated optgroup and points value for a given country, you need to access the option selected
let opt = countrySelect.options[countrySelect.selectedIndex]
let optgrp = opt.closest('optgroup');
let continent = optgrp.label
let points = optgrp.dataset.points
let country = countrySelect.value
let countryname = opt.innerText
console.log(`You selected the country ${countryname} (value ${country}) that is in ${continent} for ${points} points`);
var scholarshipGrade = document.getElementById("scholar_grade")
var form = document.getElementById("form")
var age = document.getElementById("age")
var fname = document.getElementById("fname")
var mname = document.getElementById("mname")
var lname = document.getElementById("name")
let countrySelect = document.querySelector('#select-country')
var ageGrade = 0
var countryGrade = 0
var subjectGrade = 0;
scholarshipGrade = ageGrade + countryGrade + subjectGrade
form.addEventListener('submit', function(e) {
e.preventDefault()
// country stuff
let opt = countrySelect.options[countrySelect.selectedIndex]
let optgrp = opt.closest('optgroup');
let continent = optgrp.label
let points = optgrp.dataset.points
let country = countrySelect.value
let countryname = opt.innerText
console.log(`You selected the country ${countryname} (value ${country}) that is in ${continent} for ${points} points`);
// age stuff
if (age.value >= 18 && age.value <= 24) {
ageGrade = 100
} else if (age.value >= 25 && age.value <= 30) {
ageGrade = 80
} else if (age.value >= 31 && age.value <= 35) {
ageGrade = 50
} else if (age.value >= 36 && age.value <= 40) {
ageGrade = 30
} else if (age.value >= 41) {
ageGrade = 10
}
})
body {
background-color: gray;
}
h1 {
text-align: center;
}
p {
text-align: center;
}
input[type=text],
select,
textarea,
input[type=email] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
<h1>Apply For Scholarship</h1>
<div>
<p>You can apply for a scholarship here, check if you qualify after filling the following fields,after all fields are filled submit the form</p>
</div>
<form id="form" name="form">
<label> Firstname </label>
<input type="text" name="firstname" id="fname" /> <br> <br>
<label> Middlename: </label>
<input type="text" name="middlename" id="mname" /> <br> <br>
<label> Lastname: </label>
<input type="text" name="lastname" id="lname" /> <br> <br>
<br>
<label>
Gender :
</label>
<input type="radio" name="male" /> Male
<input type="radio" name="female" /> Female
<br>
<br>
<label>Enter your age: </label>
<input type="number" id="age" name="num" min="18" max="60"><br> <br>
<label>
Phone :
</label>
<input type="text" name="phone" /> <br> <br> Address
<br>
<textarea cols="80" rows="5" value="address">
</textarea>
<br> <br> Email:
<input type="email" id="email" name="email" /> <br>
<br> <br>
<label for="country">select your country</label> <br>
<select id="select-country" name="country">
<option value="" selected="">Select country</option>
<optgroup data-points='30' label="Africa" id="africa">
<option value="DZ">Algeria</option>
<option value="AO">Angola</option>
<option value="BJ">Benin</option>
<option value="BW">Botswana</option>
<option value="BF">Burkina Faso</option>
<option value="BI">Burundi</option>
<option value="CM">Cameroon</option>
<option value="CV">Cape Verde</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="KM">Comoros</option>
<option value="CG">Congo</option>
<option value="CD">Congo, the Democratic Republic of the</option>
<option value="DJ">Dijibouti</option>
<option value="EG">Egypt</option>
<option value="GQ">Equatorial Guinea</option>
<option value="ER">Eritrea</option>
<option value="ET">Ethiopia</option>
<option value="GA">Gabon</option>
<option value="GM">Gambia</option>
<option value="GH">Ghana</option>
<option value="GN">Guinea</option>
<option value="GW">Guinea-Bissau</option>
<option value="CI">Cote d'Ivoire (Ivory Coast)</option>
<option value="KE">Kenya</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</option>
<option value="MG">Madagascar</option>
<option value="MW">Malawi</option>
<option value="ML">Mali</option>
<option value="MR">Mauritania</option>
<option value="MU">Mauritius</option>
<option value="YT">Mayotte</option>
<option value="MA">Morocco</option>
<option value="MZ">Mozambique</option>
<option value="NA">Namibia</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="RE">Reunion</option>
<option value="RW">Rwanda</option>
<option value="ST">Sao Tome and Principe</option>
<option value="SH">Saint Helena</option>
<option value="SN">Senegal</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SO">Somalia</option>
<option value="ZA">South Africa</option>
<option value="SS">South Sudan</option>
<option value="SD">Sudan</option>
<option value="SZ">Swaziland</option>
<option value="TZ">Tanzania</option>
<option value="TG">Togo</option>
<option value="TN">Tunisia</option>
<option value="UG">Uganda</option>
<option value="EH">Western Sahara</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</optgroup>
<optgroup data-points='20' label="North America" class="namerica">
<option value="US">United States</option>
<option value="UM">United States Minor Outlying Islands</option>
<option value="CA">Canada</option>
<option value="MX">Mexico</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AW">Aruba</option>
<option value="BS">Bahamas</option>
<option value="BB">Barbados</option>
<option value="BZ">Belize</option>
<option value="BM">Bermuda</option>
<option value="VG">British Virgin Islands</option>
<option value="KY">Cayman Islands</option>
<option value="CR">Costa Rica</option>
<option value="CU">Cuba</option>
<option value="DM">Dominica</option>
<option value="DO">Dominican Republic</option>
<option value="SV">El Salvador</option>
<option value="GD">Grenada</option>
<option value="GP">Guadeloupe</option>
<option value="GT">Guatemala</option>
<option value="HT">Haiti</option>
<option value="HN">Honduras</option>
<option value="JM">Jamaica</option>
<option value="MQ">Martinique</option>
<option value="MS">Montserrat</option>
<option value="AN">Netherlands Antilles</option>
<option value="NI">Nicaragua</option>
<option value="PA">Panama</option>
<option value="PR">Puerto Rico</option>
<option value="KN">Saint Kitts and Nevis</option>
<option value="LC">Saint Lucia</option>
<option value="VC">Saint Vincent and the Grenadines</option>
<option value="TT">Trinidad and Tobago</option>
<option value="TC">Turks and Caicos Islands</option>
<option value="VI">US Virgin Islands</option>
</optgroup>
<optgroup data-points='30' label="South America" class="samerica">
<option value="AR">Argentina</option>
<option value="BO">Bolivia</option>
<option value="BR">Brazil</option>
<option value="CL">Chile</option>
<option value="CO">Colombia</option>
<option value="EC">Ecuador</option>
<option value="FK">Falkland Islands (Malvinas)</option>
<option value="GF">French Guiana</option>
<option value="GY">Guyana</option>
<option value="PY">Paraguay</option>
<option value="PE">Peru</option>
<option value="SR">Suriname</option>
<option value="UY">Uruguay</option>
<option value="VE">Venezuela</option>
</optgroup>
<optgroup data-points='40' label="Asia" class="asia">
<option value="AF">Afghanistan</option>
<option value="AM">Armenia</option>
<option value="AZ">Azerbaijan</option>
<option value="BH">Bahrain</option>
<option value="BD">Bangladesh</option>
<option value="BT">Bhutan</option>
<option value="IO">British Indian Ocean Territory</option>
<option value="BN">Brunei Darussalam</option>
<option value="KH">Cambodia</option>
<option value="CN">China</option>
<option value="CX">Christmas Island</option>
<option value="CC">Cocos (Keeling) Islands</option>
<option value="GE">Georgia</option>
<option value="HK">Hong Kong</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IR">Iran</option>
<option value="IQ">Iraq</option>
<option value="IL">Israel</option>
<option value="JP">Japan</option>
<option value="JO">Jordan</option>
<option value="KZ">Kazakhstan</option>
<option value="KP">Korea, Democratic People's Republic of</option>
<option value="KR">Korea, Republic of</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Lao</option>
<option value="LB">Lebanon</option>
<option value="MY">Malaysia</option>
<option value="MV">Maldives</option>
<option value="MN">Mongolia</option>
<option value="MM">Myanmar (Burma)</option>
<option value="NP">Nepal</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PH">Philippines</option>
<option value="QA">Qatar</option>
<option value="RU">Russian Federation</option>
<option value="SA">Saudi Arabia</option>
<option value="SG">Singapore</option>
<option value="LK">Sri Lanka</option>
<option value="SY">Syria</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TH">Thailand</option>
<option value="TP">East Timor</option>
<option value="TM">Turkmenistan</option>
<option value="AE">United Arab Emirates</option>
<option value="UZ">Uzbekistan</option>
<option value="VN">Vietnam</option>
<option value="YE">Yemen</option>
</optgroup>
<optgroup data-points='10' label="Rest Of The World" class="rotws">
<option value="GB">United Kingdom</option>
<option value="AQ">Antarctica</option>
<option value="AL">Albania</option>
<option value="AD">Andorra</option>
<option value="AT">Austria</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BA">Bosnia and Herzegovina</option>
<option value="BG">Bulgaria</option>
<option value="HR">Croatia (Hrvatska)</option>
<option value="CY">Cyprus</option>
<option value="CZ">Czech Republic</option>
<option value="FR">France</option>
<option value="GI">Gibraltar</option>
<option value="DE">Germany</option>
<option value="GR">Greece</option>
<option value="VA">Holy See (Vatican City State)</option>
<option value="HU">Hungary</option>
<option value="IT">Italy</option>
<option value="LI">Liechtenstein</option>
<option value="LU">Luxembourg</option>
<option value="MK">Macedonia</option>
<option value="MT">Malta</option>
<option value="MD">Moldova</option>
<option value="MC">Monaco</option>
<option value="ME">Montenegro</option>
<option value="NL">Netherlands</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="RO">Romania</option>
<option value="SM">San Marino</option>
<option value="RS">Serbia</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="ES">Spain</option>
<option value="UA">Ukraine</option>
<option value="DK">Denmark</option>
<option value="EE">Estonia</option>
<option value="FO">Faroe Islands</option>
<option value="FI">Finland</option>
<option value="GL">Greenland</option>
<option value="IS">Iceland</option>
<option value="IE">Ireland</option>
<option value="LV">Latvia</option>
<option value="LT">Lithuania</option>
<option value="NO">Norway</option>
<option value="SJ">Svalbard and Jan Mayen Islands</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="TR">Turkey</option>
<option value="AS">American Samoa</option>
<option value="AU">Australia</option>
<option value="CK">Cook Islands</option>
<option value="FJ">Fiji</option>
<option value="PF">French Polynesia (Tahiti)</option>
<option value="GU">Guam</option>
<option value="KB">Kiribati</option>
<option value="MH">Marshall Islands</option>
<option value="FM">Micronesia, Federated States of</option>
<option value="NR">Nauru</option>
<option value="NC">New Caledonia</option>
<option value="NZ">New Zealand</option>
<option value="NU">Niue</option>
<option value="MP">Northern Mariana Islands</option>
<option value="PW">Palau</option>
<option value="PG">Papua New Guinea</option>
<option value="PN">Pitcairn</option>
<option value="WS">Samoa</option>
<option value="SB">Solomon Islands</option>
<option value="TK">Tokelau</option>
<option value="TO">Tonga</option>
<option value="TV">Tuvalu</option>
<option value="VU">Vanuatu</option>
<option valud="WF">Wallis and Futuna Islands</option>
</optgroup>
</select><br><br>
<label for="subjects"></label>
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<select name="subjects" id="subjects" filter="filter-std">
<option value="" selected="">Select subjects</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
<option value="Maths">Maths</option>
</select>
<input type="number" name="score" id="score">
<button type="submit">submit</button>
</form>
<div>
<p></p>
<p id="scholar_grade"></p>
</div>

Related

Blocking <select> when checbox is selected horizontally

I have a problem with carrying out a certain command.
After clicking on the checkbox, I want it to lock the fields horizontally.
I need the code to execute the command, after clicking on the "checkbox" it will block the hour checkbox.
I already tried If (), but it doesn't work as it should, locking me in all the fields, not just the ones I should. Can You help me?
$('body').on('change input', '.from-opening, .to-opening, .status-check', function() {
var licGroupObj = {};
licGroupObj = $('.license_group').map(function(idx, ele) {
var dayWeek = $(ele).find('.from-opening').data('days');
var hOpen = $(ele).find('.from-opening').val();
var hClosed = $(ele).find('.to-opening').val();
if ($(ele).find('.status-check:checked').val()) {
var status = 'closed';
} else {
var status = 'open';
}
return {
dayWeek,
hOpen,
hClosed,
status
};
}).get();
$('#opening_hours').val('');
$('#opening_hours').val(JSON.stringify(licGroupObj));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group row license_group">
<label for="inputEmail3" class="col-sm-2 col-form-label">Poniedziałek</label>
<div class="col-sm-4">
<select name="openingHours" class="form-control from-opening" data-days="poniedziałek">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-4">
<select name="openinHours" class="form-control to-opening">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-2">
<div class="form-check">
<input class="form-check-input status-check" type="checkbox">
<label class="form-check-label" for="flexCheckChecked">
Zamknięte?
</label>
</div>
</div>
</div>
<div class="form-group row license_group">
<label for="inputEmail3" class="col-sm-2 col-form-label">Wtorek</label>
<div class="col-sm-4">
<select name="openinHours" class="form-control from-opening" data-days="wtorek">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-4">
<select name="openinHours" class="form-control to-opening">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-2">
<div class="form-check">
<input class="form-check-input status-check" type="checkbox">
<label class="form-check-label" for="flexCheckChecked">
Zamknięte?
</label>
</div>
</div>
</div>
</div>
<input type="hidden" name="opening_hours" id="opening_hours" value="">
There you go:
$('body').on('change input', '.from-opening, .to-opening, .status-check', function() {
var licGroupObj = {};
licGroupObj = $('.license_group').map(function(idx, ele) {
var dayWeek = $(ele).find('.from-opening').data('days'),
hOpen = $(ele).find('.from-opening').val(),
hClosed = $(ele).find('.to-opening').val(),
status = false
if(ele.querySelector('.status-check').checked) status = true
if(status) ele.querySelectorAll('select').forEach(e => e.disabled = true)
else ele.querySelectorAll('select').forEach(e => e.disabled = false)
console.log(
dayWeek,
hOpen,
hClosed,
status
)
return {
dayWeek,
hOpen,
hClosed,
status
};
}).get();
$('#opening_hours').val('');
$('#opening_hours').val(JSON.stringify(licGroupObj));
})
body {
display: flex;
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div class="form-group row license_group">
<label for="inputEmail3" class="col-sm-2 col-form-label">Poniedziałek</label>
<div class="col-sm-4">
<select name="openingHours" class="form-control from-opening" data-days="poniedziałek">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-4">
<select name="openinHours" class="form-control to-opening">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-2">
<div class="form-check">
<input class="form-check-input status-check" type="checkbox">
<label class="form-check-label" for="flexCheckChecked">
Zamknięte?
</label>
</div>
</div>
</div>
<div class="form-group row license_group">
<label for="inputEmail3" class="col-sm-2 col-form-label">Wtorek</label>
<div class="col-sm-4">
<select name="openinHours" class="form-control from-opening" data-days="wtorek">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-4">
<select name="openinHours" class="form-control to-opening">
<option value="00:00">00:00</option>
<option value="00:30">00:30</option>
<option value="01:00">01:00</option>
<option value="01:30">01:30</option>
<option value="02:00">02:00</option>
<option value="03:30">03:30</option>
<option value="04:00">04:00</option>
<option value="04:30">04:30</option>
<option value="05:00">05:00</option>
<option value="05:30">05:30</option>
<option value="06:00">06:00</option>
<option value="06:30">06:30</option>
<option value="07:00">07:00</option>
<option value="07:30">07:30</option>
<option value="08:00">08:00</option>
<option value="08:30">08:30</option>
<option value="09:00">09:00</option>
<option value="09:30">09:30</option>
<option value="10:00">10:00</option>
<option value="10:30">10:30</option>
<option value="11:00">11:00</option>
<option value="11:30">11:30</option>
<option value="12:00">12:00</option>
<option value="12:30">12:30</option>
<option value="13:00">13:00</option>
<option value="13:30">13:30</option>
<option value="14:00">14:00</option>
<option value="14:30">14:30</option>
<option value="15:00">15:00</option>
<option value="15:30">15:30</option>
<option value="16:00">16:00</option>
<option value="16:30">16:30</option>
<option value="17:00">17:00</option>
<option value="17:30">17:30</option>
<option value="18:00">18:00</option>
<option value="18:30">18:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
<option value="20:00">20:00</option>
<option value="20:30">20:30</option>
<option value="21:00">21:00</option>
<option value="21:30">21:30</option>
<option value="22:00">22:00</option>
<option value="22:30">22:30</option>
<option value="23:00">23:00</option>
<option value="23:30">23:30</option>
</select>
</div>
<div class="col-sm-2">
<div class="form-check">
<input class="form-check-input status-check" type="checkbox">
<label class="form-check-label" for="flexCheckChecked">
Zamknięte?
</label>
</div>
</div>
</div>
Used some pure js here, also added console log to you see the result and of course added flex to body to make better visibility.

Why are the 2 <select> elements that are being appended to my form not looking the same as the first 2 fixed in my Form?

I have an HTML form that gets company information.
In that form, I have 2 <select multiple> elements (one for company countries and one for sectors) on which I used JQuery and Bootstrap to give them a nice style and to allow the user to choose multiple options in an easier manner.
The Problem: When the user clicks "Add Company Button" to add a new company section to the form, the appended <select multiple> elements are not being styled the same way.
The difference isn't between the first two select fields, it is rather between the first 2 select fields and the pairs that get added when you click 'Add Company'. The first two are appearing how I want them (2 rectangular boxes in which the user clicks on multiple options from the dropdown), while the others are appearing like an unstyled dropdown where you have to press Ctrl+click on the options you want to select
Please note that I removed the CSS and other parts of the page to keep things simple. Also in the appended section, I removed some options to stay within the character limit of this post
The code:
$(document).ready(function() {
$(".mul-select").select2({
placeholder: "Select Company Sectors", //placeholder
tags: true,
tokenSeparators: ['/', ',', ';', " "]
});
})
$(document).ready(function() {
$(".mul-select.countries").select2({
placeholder: "Company's Country Locations", //placeholder
tags: true,
tokenSeparators: ['/', ',', ';', " "]
});
})
$(document).ready(function() {
$("body").on("click", ".add_new_frm_field_btn", function() {
var index = $(".company-info").find(".company-info-row").length + 1;
$(".company-info").append(`
<div class="added company-info-row" style="margin:5% 0 0 0;">
<div class="company-data" style="padding:1% 4%;">
<div>
<select name="addedCompany[${index}][sectors][]" id="accountSector_${index}" class="dropdown mul-select" multiple="" tabindex="-1" aria-hidden="true">
<option value="Advertising">Advertising</option>
<option value="Aerospace">Aerospace</option>
<option value="Agriculture">Agriculture</option>
</select>
</div>
<div>
<select name="addedCompany[${index}][countries][]" id="additionalAccountLocations_${index}" class="dropdown mul-select countries" multiple="true">
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
</select>
</div>
</div>
<div class="add_del_btn_outer_comp" style="margin:0 4% 0 4%;">
<button class="add_new_frm_field_btn">
<img src="add-icon.png" alt="Add Company Button">
</button>
<button class="remove_node_btn_frm_field" disabled>
<img src="remove-icon.png" alt="Remove Company Button">
</button>
</div>
</div>
</div>
`);
$(".company-info").find(".remove_node_btn_frm_field:not(:first)").prop("disabled", false);
$(".company-info").find(".remove_node_btn_frm_field").first().prop("disabled", true);
});
});
$(document).ready(function() {
//===== delete the form feed row
$("body").on("click", ".remove_node_btn_frm_field", function() {
$(this).closest(".company-info-row").remove();
console.log("success");
});
});
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css">
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="login-box">
<div class="company-info">
<div class="company-info-row">
<div class="company-data" style="padding:1% 4%;">
<div>
<select name="company[sectors][]" id="accountSector" class="dropdown mul-select" multiple>
<option value="Advertising">Advertising</option>
<option value="Aerospace">Aerospace</option>
<option value="Agriculture">Agriculture</option>
<option value="Apparel & Accessories">Apparel & Accessories</option>
<option value="Architecture">Architecture</option>
<option value="Automotive">Automotive</option>
<option value="Banking">Banking</option>
<option value="Biotechnology">Biotechnology</option>
<option value="Building Materials & Equipment">Building Materials & Equipment</option>
<option value="Chemical">Chemical</option>
<option value="Computer">Computer</option>
<option value="Construction">Construction</option>
<option value="Consulting">Consulting</option>
<option value="Creative">Creative</option>
<option value="Culture">Culture</option>
<option value="Defense">Defense</option>
<option value="Education">Education</option>
<option value="Electric Power">Electric Power</option>
<option value="Electronics">Electronics</option>
<option value="Energy">Energy</option>
<option value="Entertainment & Leisure">Entertainment & Leisure</option>
<option value="Finance">Finance</option>
<option value="Food & Beverage">Food & Beverage</option>
<option value="Grocery">Grocery</option>
<option value="Healthcare">Healthcare</option>
<option value="Hospitality">Hospitality</option>
<option value="Insurance">Insurance</option>
<option value="Legal">Legal</option>
<option value="Manufacturing">Manufacturing</option>
<option value="Marketing">Marketing</option>
<option value="Mass Media">Mass Media</option>
<option value="Mining">Mining</option>
<option value="Music">Music</option>
<option value="Petroleum">Petroleum</option>
<option value="Publishing">Publishing</option>
<option value="Real Estate">Real Estate</option>
<option value="Retail">Retail</option>
<option value="Service">Service</option>
<option value="Shipping">Shipping</option>
<option value="Software">Software</option>
<option value="Sports">Sports</option>
<option value="Support">Support</option>
<option value="Technology">Technology</option>
<option value="Telecommunications">Telecommunications</option>
<option value="Television">Television</option>
<option value="Testing, Inspection & Certification">Testing, Inspection & Certification</option>
<option value="Transportation">Transportation</option>
<option value="Travel">Travel</option>
<option value="Venture Capital">Venture Capital</option>
<option value="Water">Water</option>
<option value="Wholesale">Wholesale</option>
</select>
</div>
<div>
<select name="company[countries][]" id="additionalAccountLocations" class="dropdown mul-select countries" multiple>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua & Barbuda">Antigua & Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bonaire">Bonaire</option>
<option value="Bosnia & Herzegovina">Bosnia & Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Ter">British Indian Ocean Ter</option>
<option value="Brunei">Brunei</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Canary Islands">Canary Islands</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Channel Islands">Channel Islands</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos Island">Cocos Island</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote DIvoire">Cote DIvoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Curaco">Curacao</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="East Timor">East Timor</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands">Falkland Islands</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Ter">French Southern Ter</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Great Britain">Great Britain</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Hawaii">Hawaii</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="Indonesia">Indonesia</option>
<option value="India">India</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Isle of Man">Isle of Man</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea North">Korea North</option>
<option value="Korea Sout">Korea South</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malaysia">Malaysia</option>
<option value="Malawi">Malawi</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Midway Islands">Midway Islands</option>
<option value="Moldova">Moldova</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Nambia">Nambia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherland Antilles">Netherland Antilles</option>
<option value="Netherlands">Netherlands (Holland, Europe)</option>
<option value="Nevis">Nevis</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau Island">Palau Island</option>
<option value="Palestine">Palestine</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Phillipines">Philippines</option>
<option value="Pitcairn Island">Pitcairn Island</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Republic of Montenegro">Republic of Montenegro</option>
<option value="Republic of Serbia">Republic of Serbia</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russia">Russia</option>
<option value="Rwanda">Rwanda</option>
<option value="St Barthelemy">St Barthelemy</option>
<option value="St Eustatius">St Eustatius</option>
<option value="St Helena">St Helena</option>
<option value="St Kitts-Nevis">St Kitts-Nevis</option>
<option value="St Lucia">St Lucia</option>
<option value="St Maarten">St Maarten</option>
<option value="St Pierre & Miquelon">St Pierre & Miquelon</option>
<option value="St Vincent & Grenadines">St Vincent & Grenadines</option>
<option value="Saipan">Saipan</option>
<option value="Samoa">Samoa</option>
<option value="Samoa American">Samoa American</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome & Principe">Sao Tome & Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Tahiti">Tahiti</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad & Tobago">Trinidad & Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks & Caicos Is">Turks & Caicos Is</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Erimates">United Arab Emirates</option>
<option value="United States of America">United States of America</option>
<option value="Uraguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Vatican City State">Vatican City State</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands (Brit)">Virgin Islands (Brit)</option>
<option value="Virgin Islands (USA)">Virgin Islands (USA)</option>
<option value="Wake Island">Wake Island</option>
<option value="Wallis & Futana Is">Wallis & Futana Is</option>
<option value="Yemen">Yemen</option>
<option value="Zaire">Zaire</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
</div>
</div>
<div class="add_del_btn_outer_comp" style="margin:0 4% 0 4%;">
<button class="add_new_frm_field_btn">
<img src="add-icon.png" alt="Add Company Button">
</button>
<button class="remove_node_btn_frm_field" disabled>
<img src="remove-icon.png" alt="Remove Company Button">
</button>
</div>
</div>
</div>
</div>
</body>
</html>
Any help in making them appear and function in the same way is highly appreciated. Thank you in advance!
My Fiddle: https://jsfiddle.net/30jwqfc5/
The first two select elements are instance of select2 and the later element is native html select. You need to instantiate select2 for the dynamically generated select elements after hitting the add company button, inside the click handler,
$('.mul-select').select2();
here is the fiddle https://jsfiddle.net/vpof3ab5/

File progress bar using jquery form and laravel

I want to implement a progress-bar in my form when uploading a file. i added the jquery form script below
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
and added a this script
<script>
var main = function(){
$("#upload").on('submit',function(e)
{
e.preventDefault();
$(this).ajaxSubmit(
{
beforeSend:function(){
$("prog").show();
$("#prog").attr('value','0');
},
uploadProgress:function(event,position,total,percentComplete)
{
$("#prog").attr('value', percentComplete);
},
success: function(data){
$("#here").html(data);
}
})
})
};
$(document).ready(main);
Any here is my form
<form method="POST" action="/store" enctype="multipart/form-data" id="upload">
#csrf
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Name</label>
<sup class="required" title="Required">*</sup>
<input type="text" class="file" title="Name" value="{{old('name')}}" name="name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Email</label>
<sup class="required" title="Required">*</sup>
<input type="text" class="file" title="Email" value="{{old('email')}}" name="email" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Phone</label>
<sup class="required" title="Required">*</sup>
<input type="number" class="file" title="Phone" value="{{old('phone')}}" name="phone" >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Country</label>
<sup class="required" title="Required">*</sup>
<select class="file" title="Country" id="country" value="{{old('country')}}" name="country">
<option value="">Select your country</option>
<option value="United States">United States</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antarctica">Antarctica</option>
<option value="Antigua and Barbuda">Antigua and Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaidjan">Azerbaidjan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bosnia-Herzegovina">Bosnia-Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Bouvet Island">Bouvet Island</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Territory">British Indian Ocean Territory</option>
<option value="Brunei Darussalam">Brunei Darussalam</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos Islands">Cocos Islands</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Congo, Democratic Republic">Congo, Democratic Republic</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote D'Ivoire">Cote D'Ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Curacao">Curacao</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibuti">Djibuti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands">Falkland Islands</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Territories">French Southern Territories</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guinea Bissau">Guinea Bissau</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Heard and MC Donald Islands">Heard and MC Donald Islands</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran">Iran</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea, Democratic People's Rep">Korea, Democratic People's Rep</option>
<option value="Korea, Republic of">Korea, Republic of</option>
<option value="Kosovo">Kosovo</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Laos">Laos</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libya">Libya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macau">Macau</option>
<option value="Macedonia">Macedonia</option>
<option value="Madagascar">Madagascar</option>
<option value="Malawi">Malawi</option>
<option value="Malaysia">Malaysia</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Micronesia">Micronesia</option>
<option value="Moldava">Moldava</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montenegro">Montenegro</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Namibia">Namibia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherlands">Netherlands</option>
<option value="Netherlands Antilles">Netherlands Antilles</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Northern Mariana Islands">Northern Mariana Islands</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau">Palau</option>
<option value="Palestine">Palestine</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Philippines">Philippines</option>
<option value="Pitcairn">Pitcairn</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Qatar">Qatar</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russian Federation">Russian Federation</option>
<option value="Rwanda">Rwanda</option>
<option value="S Georgia and S Sandwich Islands">S Georgia and S Sandwich Islands</option>
<option value="Samoa">Samoa</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome and Principe">Sao Tome and Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="St Helena">St Helena</option>
<option value="St Kitts and Nevis">St Kitts and Nevis</option>
<option value="St Lucia">St Lucia</option>
<option value="St Pierre and Miquelon">St Pierre and Miquelon</option>
<option value="St Vincent and Grenadines">St Vincent and Grenadines</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syria">Syria</option>
<option value="Taiwan">Taiwan</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania">Tanzania</option>
<option value="Thailand">Thailand</option>
<option value="Timor-Leste">Timor-Leste</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad and Tobago">Trinidad and Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks and Caicos Islands">Turks and Caicos Islands</option>
<option value="Tuvalu">Tuvalu</option>
<option value="US Minor Islands">US Minor Islands</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Emirates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Uruguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Vatican City">Vatican City</option>
<option value="Venezuela">Venezuela</option>
<option value="Vietnam">Vietnam</option>
<option value="Virgin Islands (British)">Virgin Islands (British)</option>
<option value="Wallis and Futuna">Wallis and Futuna</option>
<option value="Western Sahara">Western Sahara</option>
<option value="Yemen">Yemen</option>
<option value="Yugoslavia">Yugoslavia</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Title of video</label>
<sup class="required" title="Required">*</sup>
<input type="text" name="title" title="Title of video" value="{{old('title')}}" class="file" name="video">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Regional Agency</label>
<sup class="required" title="Required">*</sup>
<select class="file" title="Regional Agency" id="state" {{old('agency')}} name="agency">
<option value="">Select your regional agency</option>
<option>Africa</option>
<option>Asia</option>
<option>Australia</option>
<option>Europe/United Kingdom</option>
<option>North America</option>
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Category</label>
<sup class="required" title="Required">*</sup>
<select class="file" title="Category" id="state" {{old('category')}} name="category">
<option value="">Select a category</option>
<option value="Traditional Rhythm (Small Band)">Traditional Rhythm (small band)</option>
<option value="Traditional Rhythm (Large Band)">Traditional Rhythm (large band)</option>
<option value="Voices and Percussion (Small Band)">Voices and Percussion (small band)</option>
<option value="Voices and Percussion (Large Band)">Voices and Percussion (large band)</option>
<option value="Melodic Percussion (Small Band)">Melodic Percussion (small band)</option>
<option value="Melodic Percussion (Large Band)">Melodic Percussion (large band)</option>
<option value="Drum Kit Solo">Drum Kit Solo</option>
<option value="Drum Line Face Off (Small Band)">Drum Line Face-off (small band)</option>
<option value="Drum Line Face Off (Large Band)">Drum Line Face-off (large band)</option>
<option value="Innovative and Creative Rhythm (Small Band)">Innovative and Creative Rhythm (small band)</option>
<option value="Innovative and Creative Rhythm (Large Band)">Innovative and Creative Rhythm (large band)</option>
</select>
</div>
</div>
<div class="container" style="margin-top:10px;">
<label style="margin-bottom:-10%;">VIDEO UPLOAD</label><hr>
<input type="file" title="Upload a Video" name="video" class="file">
<progress max="100" value="0" id="prog" style="display:none;"></progress>
<div id="here"></div>
</div>
<div class="col-md-12 col-sm-12">
<br>
<button type="submit" class="btn btn-info btn-block" disabled><i class="fa fa-save"></i> SUBMIT APPLICATION</button>
</div>
</div>
</form>
Now, it disabled my submit button and when i checked the console, i get the error message 'ajaxSubmit is not a function at HTMLFormElement'. Please what am i doing wrong?
Please, any help will be deeply appreciated.
Thanks

Prevent refresh when submitting form by POST

I'm trying to embed the following form on a page, and when people press submit, the form submits via POST and then the page scrolls down to the next slide.
However the CMS which the form is based on forces a redirect when the form is submitted, which obviously takes the user away from my page.
How can I prevent the form from redirecting? I assume I would have to prevent the submit via e.preventDefault(); and then manually write some javascript to post the form, but confused as to how to do that. So far all my attempts have just stopped the form from submitting altogether.
<form name="signup" class="bsd-signup-135" action="https://***" method="post" id="signup">
<div class="fieldset" id="bsd-field-country">
<div class="label"><label class="field">Country</label></div>
<div class="input">
<select id="country" name="country">
<option value=""></option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AR">Argentina</option>
<option value="AM">Armenia</option>
<option value="AW">Aruba</option>
<option value="AU">Australia</option>
<option value="AT">Austria</option>
<option value="AZ">Azerbaijan</option>
<option value="BS">Bahamas</option>
<option value="BH">Bahrain</option>
<option value="BD">Bangladesh</option>
<option value="BB">Barbados</option>
<option value="BY">Belarus</option>
<option value="BE">Belgium</option>
<option value="BZ">Belize</option>
<option value="BJ">Benin</option>
<option value="BM">Bermuda</option>
<option value="BT">Bhutan</option>
<option value="BO">Bolivia</option>
<option value="BA">Bosnia and Herzegovina</option>
<option value="BW">Botswana</option>
<option value="BR">Brazil</option>
<option value="VG">British Virgin Islands</option>
<option value="IO">British Indian Ocean Territory</option>
<option value="BN">Brunei</option>
<option value="BG">Bulgaria</option>
<option value="BF">Burkina Faso</option>
<option value="BI">Burundi</option>
<option value="KH">Cambodia</option>
<option value="CM">Cameroon</option>
<option value="CA">Canada</option>
<option value="CV">Cape Verde</option>
<option value="KY">Cayman Islands</option>
<option value="CF">Central African Republic</option>
<option value="TD">Chad</option>
<option value="CL">Chile</option>
<option value="CN">China</option>
<option value="CX">Christmas Island</option>
<option value="CO">Colombia</option>
<option value="KM">Comoros Islands</option>
<option value="CD">Congo, Democratic Republic of the</option>
<option value="CG">Congo, Republic of the</option>
<option value="CK">Cook Islands</option>
<option value="CR">Costa Rica</option>
<option value="CI">Cote D'ivoire</option>
<option value="HR">Croatia</option>
<option value="CU">Cuba</option>
<option value="CY">Cyprus</option>
<option value="CZ">Czech Republic</option>
<option value="DK">Denmark</option>
<option value="DJ">Djibouti</option>
<option value="DM">Dominica</option>
<option value="DO">Dominican Republic</option>
<option value="TP">East Timor</option>
<option value="EC">Ecuador</option>
<option value="EG">Egypt</option>
<option value="SV">El Salvador</option>
<option value="GQ">Equatorial Guinea</option>
<option value="ER">Eritrea</option>
<option value="EE">Estonia</option>
<option value="ET">Ethiopia</option>
<option value="FK">Falkland Islands (Malvinas)</option>
<option value="FO">Faroe Islands</option>
<option value="FJ">Fiji</option>
<option value="FI">Finland</option>
<option value="FR">France</option>
<option value="GF">French Guiana</option>
<option value="PF">French Polynesia</option>
<option value="TF">French Southern Territories</option>
<option value="GA">Gabon</option>
<option value="GM">Gambia</option>
<option value="GE">Georgia</option>
<option value="DE">Germany</option>
<option value="GH">Ghana</option>
<option value="GI">Gibraltar</option>
<option value="GR">Greece</option>
<option value="GL">Greenland</option>
<option value="GD">Grenada</option>
<option value="GP">Guadeloupe</option>
<option value="GU">Guam</option>
<option value="GT">Guatemala</option>
<option value="GN">Guinea</option>
<option value="GW">Guinea-Bissau</option>
<option value="GY">Guyana</option>
<option value="HT">Haiti</option>
<option value="VA">Holy See (Vatican City State)</option>
<option value="HN">Honduras</option>
<option value="HK">Hong Kong</option>
<option value="HU">Hungary</option>
<option value="IS">Iceland</option>
<option value="IN">India</option>
<option value="ID">Indonesia</option>
<option value="IR">Iran</option>
<option value="IQ">Iraq</option>
<option value="IE">Republic of Ireland</option>
<option value="IL">Israel</option>
<option value="IT">Italy</option>
<option value="JM">Jamaica</option>
<option value="JP">Japan</option>
<option value="JO">Jordan</option>
<option value="KZ">Kazakhstan</option>
<option value="KE">Kenya</option>
<option value="KI">Kiribati</option>
<option value="KR">South Korea</option>
<option value="XK">Kosovo</option>
<option value="KW">Kuwait</option>
<option value="KG">Kyrgyzstan</option>
<option value="LA">Laos</option>
<option value="LV">Latvia</option>
<option value="LB">Lebanon</option>
<option value="LS">Lesotho</option>
<option value="LR">Liberia</option>
<option value="LY">Libya</option>
<option value="LI">Liechtenstein</option>
<option value="LT">Lithuania</option>
<option value="LU">Luxembourg</option>
<option value="MO">Macau</option>
<option value="MK">Macedonia</option>
<option value="MG">Madagascar</option>
<option value="MW">Malawi</option>
<option value="MY">Malaysia</option>
<option value="MV">Maldives</option>
<option value="ML">Mali</option>
<option value="MT">Malta</option>
<option value="MH">Marshall Islands</option>
<option value="MQ">Martinique</option>
<option value="MR">Mauritania</option>
<option value="MU">Mauritius</option>
<option value="YT">Mayotte</option>
<option value="MX">Mexico</option>
<option value="FM">Micronesia</option>
<option value="MD">Moldova, Republic of</option>
<option value="MC">Monaco</option>
<option value="MN">Mongolia</option>
<option value="ME">Montenegro</option>
<option value="MS">Montserrat</option>
<option value="MA">Morocco</option>
<option value="MZ">Mozambique</option>
<option value="MM">Myanmar</option>
<option value="NA">Namibia</option>
<option value="NR">Nauru</option>
<option value="NP">Nepal</option>
<option value="NL">Netherlands</option>
<option value="AN">Netherlands Antilles</option>
<option value="NC">New Caledonia</option>
<option value="NZ">New Zealand</option>
<option value="NI">Nicaragua</option>
<option value="NE">Niger</option>
<option value="NG">Nigeria</option>
<option value="NU">Niue</option>
<option value="NF">Norfolk Island</option>
<option value="MP">Northern Mariana Islands</option>
<option value="NO">Norway</option>
<option value="OM">Oman</option>
<option value="PK">Pakistan</option>
<option value="PW">Palau</option>
<option value="PA">Panama</option>
<option value="PG">Papua New Guinea</option>
<option value="PY">Paraguay</option>
<option value="PE">Peru</option>
<option value="PH">Philippines</option>
<option value="PN">Pitcairn Island</option>
<option value="PL">Poland</option>
<option value="PT">Portugal</option>
<option value="PR">Puerto Rico</option>
<option value="QA">Qatar</option>
<option value="RE">Reunion</option>
<option value="RO">Romania</option>
<option value="RU">Russian Federation</option>
<option value="RW">Rwanda</option>
<option value="KN">Saint Kitts and Nevis</option>
<option value="LC">Saint Lucia</option>
<option value="VC">Saint Vincent and the Grenadines</option>
<option value="WS">Samoa</option>
<option value="SM">San Marino</option>
<option value="ST">Sao Tome and Principe</option>
<option value="SA">Saudi Arabia</option>
<option value="SN">Senegal</option>
<option value="RS">Serbia</option>
<option value="SC">Seychelles</option>
<option value="SL">Sierra Leone</option>
<option value="SG">Singapore</option>
<option value="SK">Slovakia</option>
<option value="SI">Slovenia</option>
<option value="SB">Solomon Islands</option>
<option value="SO">Somalia</option>
<option value="ZA">South Africa</option>
<option value="SS">South Sudan</option>
<option value="ES">Spain</option>
<option value="LK">Sri Lanka</option>
<option value="SH">St. Helena</option>
<option value="PM">St. Pierre and Miquelon</option>
<option value="SD">Sudan</option>
<option value="SR">Suriname</option>
<option value="SY">Syria</option>
<option value="SZ">Swaziland</option>
<option value="SE">Sweden</option>
<option value="CH">Switzerland</option>
<option value="TW">Taiwan</option>
<option value="TJ">Tajikistan</option>
<option value="TZ">Tanzania</option>
<option value="TH">Thailand</option>
<option value="TG">Togo</option>
<option value="TK">Tokelau</option>
<option value="TO">Tonga</option>
<option value="TT">Trinidad and Tobago</option>
<option value="TN">Tunisia</option>
<option value="TR">Turkey</option>
<option value="TM">Turkmenistan</option>
<option value="TC">Turks and Caicos Islands</option>
<option value="TV">Tuvalu</option>
<option value="UG">Uganda</option>
<option value="UA">Ukraine</option>
<option value="AE">United Arab Emirates</option>
<option value="GB" selected="selected">United Kingdom</option>
<option value="US">United States</option>
<option value="UY">Uruguay</option>
<option value="UZ">Uzbekistan</option>
<option value="VU">Vanuatu</option>
<option value="VE">Venezuela</option>
<option value="VN">Viet Nam</option>
<option value="VI">Virgin Islands (U.S.)</option>
<option value="WF">Wallis and Futuna Islands</option>
<option value="EH">Western Sahara</option>
<option value="YE">Yemen</option>
<option value="ZM">Zambia</option>
<option value="ZW">Zimbabwe</option>
</select>
</div>
</div>
<div class="fieldset" id="bsd-field-email">
<div class="label"><label class="field">Email</label></div>
<div class="input"><input type="email" class="text" size="48" id="email" name="email"></div>
</div>
<div class="fieldset" id="bsd-field-firstname">
<div class="label"><label class="field">First Name</label></div>
<div class="input"><input size="16" id="firstname" name="firstname" type="text"></div>
</div>
<div class="fieldset" id="bsd-field-lastname">
<div class="label"><label class="field">Last Name</label></div>
<div class="input"><input size="25" id="lastname" name="lastname" type="text"></div>
</div>
<div class="fieldset" id="bsd-field-custom-1963-group">
<div class="label"><label class="field">Radio buttons:</label></div>
<div class="input"> <input id="custom-1963_0" class="custom-1963" name="custom-1963" value="1" type="radio"><label for="custom-1963_0">Option 1</label> <input id="custom-1963_1" class="custom-1963" name="custom-1963" value="2" type="radio"><label for="custom-1963_1">Option 2</label> <input id="custom-1963_2" class="custom-1963" name="custom-1963" value="3" type="radio"><label for="custom-1963_2">Option 3</label> </div>
</div>
<div class="fieldset" id="bsd-field-email_opt_in">
<div class="label"><label class="field"></label></div>
<div class="input"><input id="email_opt_in" name="email_opt_in" type="checkbox" value="1"><label for="email_opt_in">Would you like to receive updates about our news, campaigns and appeals by email?</label></div>
</div>
<div class="fieldset" id="bsd-field-submit-btn">
<div class="label"><label class="field"></label></div>
<div class="input"><input name="submit-btn" value="Sign the petition" type="submit" id="submit_button"></div>
</div>
</form>
I got this far with the javascript, but was unsure of how to post whether a field is checked or not, or how to post radios (especially radios with a hyphen in their name/ID, which I cannot change due to CMS.
$("#signup").submit(function(event) {
event.preventDefault();
var $form = $(this),
url = $form.attr("action");
var posting = $.post(url, {
country: $("#country").val(),
email: $("#email").val(),
firstname: $("#firstname").val(),
lastname: $("#lastname").val()
});
posting.done(function(data) {
alert("Success!");
});
});

Sending form inputs to the server using jquery-ajax

I have been having problems sending form data inputs to the server. I have tried alerting each form input and its giving me empty alerts here is my code: From my code its been alerting 0. When I post normally, it works.
<script type="text/javascript">
$(function(){
//dataString = $('#form_user').serialize();
var details = new FormData(document.getElementById('form_user'));
$('#form_user').submit(function(){
$.ajax({
url:"<?= base_url('form/insertUser'); ?>",
type:"POST",
data: details,
processData: false,
contentType: false,
success: function(data){
var result = $.parseJSON(data);
alert(result.id);
},
error: function(error,status,strErr){
alert(strErr);
}
});
return false;
});
});
</script>
My Html:
<div id="user" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="myModalLabel">Add User</h4>
</div>
<div class="modal-body">
<p>
<div class ="error">
</div>
<form class="form-inline" name="form_user" id="form_user" >
<div class="row">
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span4" type="text" name="fname" placeholder="Firstname">
</div>
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span4" type="text" name="sname" placeholder="Surname">
</div>
</div>
<div class="row">
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-envelope"></i></span>
<input class="span4" type="text" placeholder="Email address" name="email">
</div>
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-th-list"></i></span>
<select name="gender" class="span4" data-placeholder="Gender" >
<option value="">Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="row">
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-th-list"></i></span>
<select name="group" class="span4" data-placeholder="Group" >
<option value="">Group</option>
<option value="1">Member</option>
<option value="2">Admin</option>
</select>
</div>
</div>
<div class="row">
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-th-list"></i></span>
<select class="chosen span4" name="country" >
<option value="" >Choose a Country...</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antarctica">Antarctica</option>
<option value="Antigua and Barbuda">Antigua and Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahamas">Bahamas</option>
<option value="Bahrain">Bahrain</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Barbados">Barbados</option>
<option value="Belarus">Belarus</option>
<option value="Belgium">Belgium</option>
<option value="Belize">Belize</option>
<option value="Benin">Benin</option>
<option value="Bermuda">Bermuda</option>
<option value="Bhutan">Bhutan</option>
<option value="Bolivia">Bolivia</option>
<option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
<option value="Botswana">Botswana</option>
<option value="Bouvet Island">Bouvet Island</option>
<option value="Brazil">Brazil</option>
<option value="British Indian Ocean Territory">British Indian Ocean Territory</option>
<option value="Brunei Darussalam">Brunei Darussalam</option>
<option value="Bulgaria">Bulgaria</option>
<option value="Burkina Faso">Burkina Faso</option>
<option value="Burundi">Burundi</option>
<option value="Cambodia">Cambodia</option>
<option value="Cameroon">Cameroon</option>
<option value="Canada">Canada</option>
<option value="Cape Verde">Cape Verde</option>
<option value="Cayman Islands">Cayman Islands</option>
<option value="Central African Republic">Central African Republic</option>
<option value="Chad">Chad</option>
<option value="Chile">Chile</option>
<option value="China">China</option>
<option value="Christmas Island">Christmas Island</option>
<option value="Cocos (Keeling) Islands">Cocos (Keeling) Islands</option>
<option value="Colombia">Colombia</option>
<option value="Comoros">Comoros</option>
<option value="Congo">Congo</option>
<option value="Congo, The Democratic Republic of The">Congo, The Democratic Republic of The</option>
<option value="Cook Islands">Cook Islands</option>
<option value="Costa Rica">Costa Rica</option>
<option value="Cote D'ivoire">Cote D'ivoire</option>
<option value="Croatia">Croatia</option>
<option value="Cuba">Cuba</option>
<option value="Cyprus">Cyprus</option>
<option value="Czech Republic">Czech Republic</option>
<option value="Denmark">Denmark</option>
<option value="Djibouti">Djibouti</option>
<option value="Dominica">Dominica</option>
<option value="Dominican Republic">Dominican Republic</option>
<option value="Ecuador">Ecuador</option>
<option value="Egypt">Egypt</option>
<option value="El Salvador">El Salvador</option>
<option value="Equatorial Guinea">Equatorial Guinea</option>
<option value="Eritrea">Eritrea</option>
<option value="Estonia">Estonia</option>
<option value="Ethiopia">Ethiopia</option>
<option value="Falkland Islands (Malvinas)">Falkland Islands (Malvinas)</option>
<option value="Faroe Islands">Faroe Islands</option>
<option value="Fiji">Fiji</option>
<option value="Finland">Finland</option>
<option value="France">France</option>
<option value="French Guiana">French Guiana</option>
<option value="French Polynesia">French Polynesia</option>
<option value="French Southern Territories">French Southern Territories</option>
<option value="Gabon">Gabon</option>
<option value="Gambia">Gambia</option>
<option value="Georgia">Georgia</option>
<option value="Germany">Germany</option>
<option value="Ghana">Ghana</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Greece">Greece</option>
<option value="Greenland">Greenland</option>
<option value="Grenada">Grenada</option>
<option value="Guadeloupe">Guadeloupe</option>
<option value="Guam">Guam</option>
<option value="Guatemala">Guatemala</option>
<option value="Guinea">Guinea</option>
<option value="Guinea-bissau">Guinea-bissau</option>
<option value="Guyana">Guyana</option>
<option value="Haiti">Haiti</option>
<option value="Heard Island and Mcdonald Islands">Heard Island and Mcdonald Islands</option>
<option value="Holy See (Vatican City State)">Holy See (Vatican City State)</option>
<option value="Honduras">Honduras</option>
<option value="Hong Kong">Hong Kong</option>
<option value="Hungary">Hungary</option>
<option value="Iceland">Iceland</option>
<option value="India">India</option>
<option value="Indonesia">Indonesia</option>
<option value="Iran, Islamic Republic of">Iran, Islamic Republic of</option>
<option value="Iraq">Iraq</option>
<option value="Ireland">Ireland</option>
<option value="Israel">Israel</option>
<option value="Italy">Italy</option>
<option value="Jamaica">Jamaica</option>
<option value="Japan">Japan</option>
<option value="Jordan">Jordan</option>
<option value="Kazakhstan">Kazakhstan</option>
<option value="Kenya">Kenya</option>
<option value="Kiribati">Kiribati</option>
<option value="Korea, Democratic People's Republic of">Korea, Democratic People's Republic of</option>
<option value="Korea, Republic of">Korea, Republic of</option>
<option value="Kuwait">Kuwait</option>
<option value="Kyrgyzstan">Kyrgyzstan</option>
<option value="Lao People's Democratic Republic">Lao People's Democratic Republic</option>
<option value="Latvia">Latvia</option>
<option value="Lebanon">Lebanon</option>
<option value="Lesotho">Lesotho</option>
<option value="Liberia">Liberia</option>
<option value="Libyan Arab Jamahiriya">Libyan Arab Jamahiriya</option>
<option value="Liechtenstein">Liechtenstein</option>
<option value="Lithuania">Lithuania</option>
<option value="Luxembourg">Luxembourg</option>
<option value="Macao">Macao</option>
<option value="Macedonia, The Former Yugoslav Republic of">Macedonia, The Former Yugoslav Republic of</option>
<option value="Madagascar">Madagascar</option>
<option value="Malawi">Malawi</option>
<option value="Malaysia">Malaysia</option>
<option value="Maldives">Maldives</option>
<option value="Mali">Mali</option>
<option value="Malta">Malta</option>
<option value="Marshall Islands">Marshall Islands</option>
<option value="Martinique">Martinique</option>
<option value="Mauritania">Mauritania</option>
<option value="Mauritius">Mauritius</option>
<option value="Mayotte">Mayotte</option>
<option value="Mexico">Mexico</option>
<option value="Micronesia, Federated States of">Micronesia, Federated States of</option>
<option value="Moldova, Republic of">Moldova, Republic of</option>
<option value="Monaco">Monaco</option>
<option value="Mongolia">Mongolia</option>
<option value="Montenegro">Montenegro</option>
<option value="Montserrat">Montserrat</option>
<option value="Morocco">Morocco</option>
<option value="Mozambique">Mozambique</option>
<option value="Myanmar">Myanmar</option>
<option value="Namibia">Namibia</option>
<option value="Nauru">Nauru</option>
<option value="Nepal">Nepal</option>
<option value="Netherlands">Netherlands</option>
<option value="Netherlands Antilles">Netherlands Antilles</option>
<option value="New Caledonia">New Caledonia</option>
<option value="New Zealand">New Zealand</option>
<option value="Nicaragua">Nicaragua</option>
<option value="Niger">Niger</option>
<option value="Nigeria">Nigeria</option>
<option value="Niue">Niue</option>
<option value="Norfolk Island">Norfolk Island</option>
<option value="Northern Mariana Islands">Northern Mariana Islands</option>
<option value="Norway">Norway</option>
<option value="Oman">Oman</option>
<option value="Pakistan">Pakistan</option>
<option value="Palau">Palau</option>
<option value="Palestinian Territory, Occupied">Palestinian Territory, Occupied</option>
<option value="Panama">Panama</option>
<option value="Papua New Guinea">Papua New Guinea</option>
<option value="Paraguay">Paraguay</option>
<option value="Peru">Peru</option>
<option value="Philippines">Philippines</option>
<option value="Pitcairn">Pitcairn</option>
<option value="Poland">Poland</option>
<option value="Portugal">Portugal</option>
<option value="Puerto Rico">Puerto Rico</option>
<option value="Qatar">Qatar</option>
<option value="Reunion">Reunion</option>
<option value="Romania">Romania</option>
<option value="Russian Federation">Russian Federation</option>
<option value="Rwanda">Rwanda</option>
<option value="Saint Helena">Saint Helena</option>
<option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
<option value="Saint Lucia">Saint Lucia</option>
<option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option>
<option value="Saint Vincent and The Grenadines">Saint Vincent and The Grenadines</option>
<option value="Samoa">Samoa</option>
<option value="San Marino">San Marino</option>
<option value="Sao Tome and Principe">Sao Tome and Principe</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="Senegal">Senegal</option>
<option value="Serbia">Serbia</option>
<option value="Seychelles">Seychelles</option>
<option value="Sierra Leone">Sierra Leone</option>
<option value="Singapore">Singapore</option>
<option value="Slovakia">Slovakia</option>
<option value="Slovenia">Slovenia</option>
<option value="Solomon Islands">Solomon Islands</option>
<option value="Somalia">Somalia</option>
<option value="South Africa">South Africa</option>
<option value="South Georgia and The South Sandwich Islands">South Georgia and The South Sandwich Islands</option>
<option value="South Sudan">South Sudan</option>
<option value="Spain">Spain</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Sudan">Sudan</option>
<option value="Suriname">Suriname</option>
<option value="Svalbard and Jan Mayen">Svalbard and Jan Mayen</option>
<option value="Swaziland">Swaziland</option>
<option value="Sweden">Sweden</option>
<option value="Switzerland">Switzerland</option>
<option value="Syrian Arab Republic">Syrian Arab Republic</option>
<option value="Taiwan, Republic of China">Taiwan, Republic of China</option>
<option value="Tajikistan">Tajikistan</option>
<option value="Tanzania, United Republic of">Tanzania, United Republic of</option>
<option value="Thailand">Thailand</option>
<option value="Timor-leste">Timor-leste</option>
<option value="Togo">Togo</option>
<option value="Tokelau">Tokelau</option>
<option value="Tonga">Tonga</option>
<option value="Trinidad and Tobago">Trinidad and Tobago</option>
<option value="Tunisia">Tunisia</option>
<option value="Turkey">Turkey</option>
<option value="Turkmenistan">Turkmenistan</option>
<option value="Turks and Caicos Islands">Turks and Caicos Islands</option>
<option value="Tuvalu">Tuvalu</option>
<option value="Uganda">Uganda</option>
<option value="Ukraine">Ukraine</option>
<option value="United Arab Emirates">United Arab Emirates</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="United States Minor Outlying Islands">United States Minor Outlying Islands</option>
<option value="Uruguay">Uruguay</option>
<option value="Uzbekistan">Uzbekistan</option>
<option value="Vanuatu">Vanuatu</option>
<option value="Venezuela">Venezuela</option>
<option value="Viet Nam">Viet Nam</option>
<option value="Virgin Islands, British">Virgin Islands, British</option>
<option value="Virgin Islands, U.S.">Virgin Islands, U.S.</option>
<option value="Wallis and Futuna">Wallis and Futuna</option>
<option value="Western Sahara">Western Sahara</option>
<option value="Yemen">Yemen</option>
<option value="Zambia">Zambia</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
</div>
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span4" type="number" name="phone" placeholder="Phone" >
</div>
</div>
<div class="row">
<div class="input-prepend span4 form-span">
<span class="add-on"><i class="icon-key"></i></span>
<input class="span4" type="password" name="password" placeholder="Password">
</div>
<div class="input-prepend span4 form-span">
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</div>
</div>
</form>
</p>
</div>
<div class="modal-footer">
<p></p>
</div>
</div>
Controller:
public function insertUser(){
$this->load->library('form_validation');
$this->form_validation->set_rules('fname','Firstname','trim|required|xss_clean');
$this->form_validation->set_rules('sname','Surname','trim|required|xss_clean');
$this->form_validation->set_rules('gender','Gender','trim|required|xss_clean');
$this->form_validation->set_rules('phone','Phone','trim|required|numeric|xss_clean');
$this->form_validation->set_rules('email','Email','trim|required|xss_clean|valid_email|is_unique[users.email]');
$this->form_validation->set_rules('password','Password','trim|required|xss_clean');
$this->form_validation->set_rules('group','Group','trim|required|xss_clean');
if($this->form_validation->run() == FALSE){
$json = array('id'=>0,'msg'=>validation_errors('<p class="error">','</p>'));
echo json_encode($json);
}else{
//insertion takes place here
$this->load->model('admin_model');
$fname = $this->input->post('fname');
$sname = $this->input->post('sname');
$gender = $this->input->post('gender');
$phone = $this->input->post('phone');
$password = $this->input->post('password');
$username = $this->input->post('email');
$country = $this->input->post('country');
$group = $this->input->post('group');
$data = array(
'email'=>$username,
'password'=>$password,
'active'=>1,
'fname'=>$fname,
'lname'=>$sname,
'phone'=>$phone,
'phone'=>$phone,
'country'=>$country,
'gender'=>$gender,
'group'=>$group
);
$table = 'users';
$this->admin_model->insert($table,$data);
$json = array('id'=>1,'msg'=>'User Successfully Created!!!');
echo json_encode($json);
}
}
Since you're using jQuery, you can use .serialize() jQuery method.
var details = $('#form_user').serialize();
This will solve your problem.
You can use
contentType: 'json'
And then you will not need to use 'parseJSON'. Your data will be received already as a Javascript Object.

Categories

Resources