locked
Insert data using Jquery RRS feed

  • Question

  • User639567535 posted

    I try to insert data using Jquery and there is textbox and select options Html

    <input type="text" class="input-sm" id="txt_repeat" />
                                <select id="dura_values">
                                    <option>da(s)</option>
                                    <option>We(s)</option>
    
                                </select>

    JQUERY

     success: function (result) {
                    var insert = JSON.parse(result.d).response;
               $("#txt_repeat" + ins.Frequency).html(ins.Frequency);
               $("#dura_values").find("option:contains("+ins.Freq_Du+")");
                },

    Now how i display  inserting data in table also data is not insert in table

    Static function

      public static string Insert_master_services(string Frequency,string Freq_Du)
        {
            Data insertt=new Data();
            tbl_fl_Master_List t = new tbl_fl_Master_List(); 
            t.Frequency = Frequency;
            t.Freq_Du = Freq_Du;
            insertt.SaveChanges();
            return new JavaScriptSerializer().Serialize(t);
        }
    Thursday, October 20, 2016 12:27 PM

Answers

  • User-707554951 posted

    Hi Bakhtawar,

     $("#dura_values" + ins.Freq_Du).html(ins.Freq_Du);


    From your description and code, are you want to use the code above to set the value of  your input’s option? If that the case, the reason why you encounter Uncaught Error is that you didn’t use Jquery selector correctly. In other word. JQUERY can’t find an element(it’s id is dura_valuesWe(s)).

    Since, I suggest you could replace your code with the code below:

    $('#dura_values option:contains(ins.Freq_Du)').html(ins.Freq_Du);

    also data is not insert in table

    For the problem above, I supposed that you forget use Add() method to add t to insert.

    Try the code below:

     public static string Insert_master_services(string Frequency, string Freq_Du)
            {
                Data insertt = new Data();
                tbl_fl_Master_List t = new tbl_fl_Master_List();
                t.Frequency = Frequency;
                t.Freq_Du = Freq_Du;
                insertt.Add(t);
                insertt.SaveChanges();
                return new JavaScriptSerializer().Serialize(t);
            }

    Best regards
    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 21, 2016 9:06 AM