0
  1. First row is working fine but
  2. click on add row row is added cites is not cleared and
  3. based on state selection city is not bind in 2nd row.

    var categoryinfo= {
    "Andhra-Pradesh":{
    "Vijayawada":[],
    "Visakhapatnam":[],
    "Kadapa":[]
    },
    
    "Maharastra":{
    "Mumbai":[],
    "Pune":[]
    },
    "Telangana":{
    "Secunderabad":[],
    "Hyderabad":[],
    "Khammam":[]
    },
    }
    
    
    $(document).ready(function(){
    getlists();
    });
    function  getlists() {
    var stateSel = document.getElementById("stateSel"); 
    var citySel = document.getElementById("citySel");
    for (var state in categoryinfo) {
    stateSel.options[stateSel.options.length] = new Option(state, 
    state);
    }
    stateSel.onchange = function () {        
    citySel.length = 1;                  
    if (this.selectedIndex < 1){
    citySel.options[0].text = "Please select state."
    return; 
    }
    citySel.options[0].text = "Please select city."
    for (var city in categoryinfo[this.value]) {
    citySel.options[citySel.options.length] = new Option(city, city);
    }
    if (citySel.options.length==2) {
    citySel.selectedIndex=1;
    
    }  
    
    }
    
    }
    
    
    //Inserting data
    
    siteurl = "https://neodadar1.sharepoint.com/sites/Masterpage1";
    function insert(){
    var clientcontext = new SP.ClientContext(siteurl);
    var list = clientcontext.get_web().get_lists().getByTitle('task');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var state = document.getElementById('stateSel').value;
    var city = document.getElementById('citySel').value;
    this.oListItem = list.addItem(itemCreateInfo);
    oListItem.set_item('state', state);  
    oListItem.set_item('city', city);
    oListItem.update();  
    clientcontext.load(oListItem);  
    clientcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));  
    }
    function onQuerySucceeded()  
    {  
    alert('Item created Successfully');  
    }  
    
    function onQueryFailed(sender, args)  
    {  
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
    }  
    
    //For redirect to another page
    
    function Redirect()
    {
    window.location="https://neodadar1.sharepoint.com/sites/Masterpage1/SitePages/gridtask.aspx";
    }
    
    
    //validations
    
    function ddlValidate() {
    var e = document.getElementById("stateSel");
    var optionSelIndex = e.options[e.selectedIndex].value;
    var optionSelectedText = e.options[e.selectedIndex].text;
    if (optionSelIndex == 0) {
    alert("Please select a state");
    return false;
    }
    var e = document.getElementById("citySel");
    var optionSelIndex = e.options[e.selectedIndex].value;
    var optionSelectedText = e.options[e.selectedIndex].text;
    if (optionSelIndex == 0) {
    alert("Please select a city");
    return false;
    }
    insert();
    }
    
    
    $(document).ready(function(){
    $("#addrow").click(function(){          
    var e = document.getElementById("stateSel");
    var optionSelIndex = e.options[e.selectedIndex].value;
    var optionSelectedText = e.options[e.selectedIndex].text;
    if (optionSelIndex == 0) {
    alert("Please select a state");
    return false;
    }
    var e = document.getElementById("citySel");
    var optionSelIndex = e.options[e.selectedIndex].value;
    var optionSelectedText = e.options[e.selectedIndex].text;
    if (optionSelIndex == 0) {
    alert("Please select a city");
    return false;
    }
    
    addRow("tbl");
    });
    var addRow = function(tbl) {
    var table = document.getElementById(tbl); 
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    
    for (var i = 0; i<colCount; i++) {
    var newcell = row.insertCell(i);
    
    newcell.innerHTML = table.rows[0].cells[i].innerHTML;
    newcell.childNodes[0].selectedIndex = 0;
    }
    };
    });
    

    Look at **strong text**here

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.