Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Note: For State And  City No Javascript Validation Works. And Also Intersting Thing On State And City Please Check That </h1>
<h1>First go to the end and give submit and check that validation</h1>
<h1>Done By MahilanJayaprakash Email : mahilan.jp@gmail.com</h1>
<h1>Student Form | MJD</h1>

    <form aciton ="/myaction.php" name="myForm" onsubmit="return validateForm()" method="post">
        <table class="center" cellpadding = "10">
            <br>
            <br>
            <br>
            <br>
            <br>
            <tr>
               <td> <div class="formdesign" id="name">
                    Name: <input type="text" name="fname" required><b><span class="formerror"> </span></b>
                </div> </td>
            </tr>
            
    
           <tr>
               <td> <div class="formdesign" id="surname">
                Surname: <input type="text" name="surname" required><b><span class="formerror"> </span></b>
            </div> </td>
        </tr>
    
           <tr> 
               <td><div class="formdesign" id="email">
                Email: <input type="email" name="femail" required><b><span class="formerror"> </span></b>
            </div></td>
        </tr>
           <tr>
           <td> <div class="formdesign" id="phone">
                Phone: <input type="phone" name="fphone" required><b><span class="formerror"></span></b>
            </div></td>
        </tr>
        <tr>
            <td><div class="formdesign" id="dob">
               DOB : <input type="date" name="dob" required><b><span class="formerror"></span></b>
            </div></td>
        </tr>
        <tr>
           <td>
               
            <div class="formdesign" id="address1">
            Address 1 : <input type="address" name="address1" cols="30" rows="4" required><b><span class="formerror"></span></b>
             </div>
           </td> 
        </tr>
            <tr>
              <td> <div class="formdesign" id="address2">
            Address2: <input type="address" name="address2" cols="30" rows="4" required><b><span class="formerror"></span></b>
             </div></td>
            </tr>
            
            <tr>
                <td>
                    <div class="formdesign" id="gender">
                        Gender:
                        Male: <input type="radio" name="gender" ud="Male" required><b><span class="formerror"></span></b>
                        Female: <input type="radio" name="gender" ud="Female" required><b><span class="formerror"></span></b>
                        Others: <input type="radio" name="gender" ud="Others" required><b><span class="formerror"></span></b>
                      </div>
                </td>
            </tr>
     
             <tr>
                 <td><div class="formdesign" id="state">
                   State: <select id="state" size="1" onchange="makeSubmenu(this.value)">
                        <option value="U+2610">Select State ☑ </option>
                        <option value="Andhra_Pradesh">Andhra Pradesh</option>
                        <option value="Assam">Assam</option>
                        <option value="Bihar">Bihar</option>    
                        <option value="Chhattisgarh">Chhattisgarh</option>
                        <option value="Puducherry">Puducherry</option>
                        <option value="Goa">Goa</option>
                        <option value="Gujarat">Gujarat</option>
                        <option value="Haryana">Haryana</option>
                        <option value="Himachal_Pradesh">Himachal Pradesh</option>
                        <option value="Jharkhand">Jharkhand</option>
                        <option value="Karnataka">Karnataka</option>
                        <option value="Kerala">Kerala</option>
                        <option value="Madhya_Pradesh">Madhya Pradesh</option>
                        <option value="Maharashtra">Maharashtra</option>
                        <option value="Manipur">Manipur</option>
                        <option value="Meghalaya">Meghalaya</option>
                        <option value="Mizoram">Mizoram</option>
                        <option value="Nagaland">Nagaland</option>
                        <option value="Odisha">Odisha</option>
                        <option value="Punjab">Punjab</option>
                        <option value="Rajasthan">Rajasthan</option>
                        <option value="Sikkim">Sikkim</option>
                        <option value="TamilNadu">Tamil Nadu</option>
                        <option value="Telangana">Telangana</option>
                        <option value="Tripura">Tripura</option>
                        <option value="UttarPradesh">Uttar Pradesh</option>
                        <option value="Uttarakhand">Uttarakhand</option>
                        <option value="WestBengal">West Bengal</option>
                    </select> </div></td>
             </tr>   
                
            <tr>
                <td>
                    <div class="formdesign" id="city">
                        City: <select id="citySelect" size="1" >
                            <option value="" disabled selected>Choose City</option>
                            <option></option>
                        </select>
                    </div>
                </td>
            </tr>
                <tr>
                    <td>
                        <div class="formdesign" id="pincode">
                            Pincode: <input type="pincode" name="pincode"  required><b><span class="formerror"></span></b>
                         </div> 
                    </td>
                </tr>
               <tr>
                   <td>  <input class="but" type="submit" value="Submit"></td>
               </tr>
          
        </table>   
    </form>
              
            
!

CSS

              
                          *{
  margin: 0;
  padding: 0;
}
body{
  background-color: aquamarine;
}
.formerror {
      color: red;
}
.center {
  margin-left: auto;
  margin-right: auto;
}
h1{
  text-align: center;
  color: white;

}
              
            
!

JS

              
                  function clearErrors(){

errors = document.getElementsByClassName('formerror');
for(let item of errors)
{
    item.innerHTML = "";
}


}
function seterror(id, error){

element = document.getElementById(id);
element.getElementsByClassName('formerror')[0].innerHTML = error;

}

function validateForm(){
var returnval = true;
clearErrors();

var name = document.forms['myForm']["fname"].value;
if (name.length<5){
    seterror("name", "*Length of name is too short");
    returnval = false;
}

if (name.length == 0){
    seterror("name", "*Length of name cannot be zero!");
    returnval = false;
}

var surname = document.forms['myForm']["surname"].value;
if (surname.length<5){
    seterror("surname", "*Length of surname is too short");
    returnval = false;
}
if (surname.length == 0){
    seterror("surname", "*Length of surname cannot be zero!");
    returnval = false;
}
var email = document.forms['myForm']["femail"].value;
if (email.length>15){
    seterror("email", "*Email length is too long");
    returnval = false;
}

var phone = document.forms['myForm']["fphone"].value;
if (phone.length != 10){
    seterror("phone", "*Phone number should be of 10 digits!");
    returnval = false;
}

var dob = document.forms['myForm']["dob"].value;

var address1 = document.forms['myForm']["address1"].value;
if (address1.length < 15){
    seterror("address1", "* Your Address Line 1 must be 15 to 100 characters");
    returnval = false;
}

var address2 = document.forms['myForm']["address2"].value;
if (address1.length < 10){
    seterror("address2", "* Your Address Line 2 must be 10 to 30     characters");
    returnval = false;
}

var gender = document.forms['myForm']["gender"].value;
var state = document.forms['myForm']["state"].value;
var citySelect = document.forms['myForm']["citySelect"].value;
var pincode = document.forms['myForm']["pincode"].value;


return returnval;
}

var citiesByState = {
Andhra_Pradesh: ["Select City","Visakhapatnam","Vijayawada","	Guntur","Nellore","Kurnool","Kakinada","Rajamahendravaram","Kadapa","Tirupati","Anantapuram","Vizianagaram","Eluru","Nandyal","Ongole","Adoni",
"Madanapalle","Machilipatnam","Tenali","Proddatur","Chittoor","Hindupur","Srikakulam","Bhimavaram","Gudivada","Guntakal","Tadepalligudem","Dharmavaram","Narasaraopet","Tadipatri","Mangalagiri",
"Chilakaluripet"],
Assam: ["Select City","Guwahati","Silchar","Dibrugarh"],
Bihar: ["Select City","West Champaran","Gaya","Arwal","East Champaran"],
Chhattisgarh: ["Select City","Raipur","Bilaspur","Ambagarh Chowki"],
Puducherry: ["Select City","Irumbai","Karaikal","Karaikal Bazaar","Karaikalmedu"],
Goa: ["Select City","Panaji","Calangute","Vasacoda Gama","Margao"],
Gujarat: ["Select City","Ahmedabad","Amreli","Banaskantha","Bharuch","Bhavnagar","Dang","Jamnagar"],
Haryana: ["Select City","Faridabad","Gurugram","Panipat","Ambala","Bhiwani"],
Himachal_Pradesh: ["Select City","Shimla","Dharamsala","Solan","Mandi","Nako"],
Jharkhand: ["Select City","Jamshedpur","Dhanbad","Ranchi","Bokaro Steel City","Chirkunda"],
Karnataka: ["Select City","Gulbarga","Shimoga","Bangalore","Mangalore","Mysore"],
Odisha: ["Select City","Bhubaneswar","Puri","Cuttack"],
Maharashtra: ["Select City","Mumbai","Pune","Nagpur"],
Kerala: ["Select City","Kochi","Kanpur","Thiruvananthapuram","Kozhikode","Malappuram"],
Madhya_Pradesh: ["Select City","Indore","Bhopal","Gwalior","Jabalpur","Ujjain"],
Maharashtra: ["Select City","Mumbai","Lonavla","Velhe","Nashik","Panvel"],
Manipur: ["Select City","Imphal West","Imphal East","Thoubal","Myanmar","Bishnupur"],
Meghalaya: ["Select City","Shillong","Cherrapunjee","Tura","Nongstoin","Mairang"],
Mizoram: ["Select City","Aizawl","Champhai","Khawbung","Thenzawl","Lunglei"],
Nagaland: ["Select City","Dimapur","Kohima","Soma","Tuensang","Peren"],
Punjab: ["Select City","Ludhiana","Amritsar","Jalandhar","Patiala","Chandigarh"],
Rajasthan: ["Select City","Jaipur","Jodhpur","Ajmer","Jhalawar","Skekhwati"],
Sikkim: ["Select City","Gangtok","Gyalshing","Jorethang","Mangan","East Sikkim"],
TamilNadu: ["Select City","Chennai","Salem","Erode","Namakkal","Madurai","Thanjavur","Ooty","Kodaikanal","Kanchipuram","Theni","Pudukottai"],
Telangana: ["Select City","Hyderabad","Warangal","Nizamabad","Khammam","Bhadradri Kothagudem"],
Tripura: ["Select City","Kamalpur","Agartala","Ambassa","Mohanpur","Melaghar"],
UttarPradesh: ["Select City","Kanpur","Lucknow","Ghaziabad","Agra","Meerut"],
Uttarakhand: ["Select City","Dehradun","Haridwar","Kashipur","Roorkee","Pantnagar"],
WestBengal: ["Select City","Kolkata","Darjeeling","Kharagpur","Krishnanagar","Bangaon"] 
}

function makeSubmenu(value)
{
 if(value.length==0) document.getElementById("city").innerHTML = "<option></option>";
 else 
 {
     var citiesOptions = "";

     for(cityId in citiesByState[value]) 
     {
         citiesOptions+="<option>"+citiesByState[value][cityId]+"</option>";
     }

     document.getElementById("citySelect").innerHTML = citiesOptions;

 }
}
              
            
!
999px

Console