title: mvc Get a value of element in different cshtml with jquery
body: <p>I have a page ("mypage.cshtml") and two partial view page ( partial1.cshtml, partial2.cshtml )
  when Im in mypage click a button and display a modal which call partial1 with               @Html.Partial("patial1") in a modal(bootstrap modal). it consist of html. when I a click a button on this modal it calls another modal consist of partial2.. </p>
  
  <p>Here is the issue; When I load the page begining (in mypage ) I need to get the value of checkbox that standing in second modal, that is partial2. 
  During I view this modal I can get this value with this: </p>
  
  <pre><code>$("input[type='checkbox'][id='4']").val();
  </code></pre>
  
  <p>it gives me the value which I expect but at the begining(in mypage.cshtml) this returns "undefined" :S
  I couldnt understand this stuation both of these modal located in mypage but why I cant get these elements values untill I reach them ?   </p>
  
  <p>here is view mypage:</p>
  
  <pre><code>&lt;div id="stack1" class="modal fade" tabindex="-1" data-width="400"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&lt;/button&gt;
                  &lt;h4 class="modal-title"&gt;@Model.Kurulus.TESIS_ADI&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;form id="formKaydet" method="post" action="../KurulusBilgileri/KurulusBilgileriniGuncelle"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-md-12"&gt;
                              @Html.Partial("KurulusBilgileriniGuncelle", Model)
                          &lt;/div&gt;
                          &lt;div class="modal-footer"&gt;
                              &lt;input type="hidden" name="SANAYI_TIPI" id="input_id" /&gt;
                              &lt;input type="hidden" name="SANAYI_TIPI_DIGER" id="input_sanayitipi" /&gt;
                              &lt;button type="button" data-dismiss="modal" class="btn default"&gt;Geri&lt;/button&gt;
                              &lt;a class="btn orange" onclick="sanayitipleriKaydet()"&gt;Kaydet A&lt;/a&gt;
  
  
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="stack2" class="modal fade" tabindex="-1"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&lt;/button&gt;
                  &lt;h4 class="modal-title"&gt;@Model.Kurulus.TESIS_ADI&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-md-12"&gt;
                          @Html.Partial("SanayiTipiSecim", Model.SanayitipiModel)
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  @*&lt;button type="button" data-dismiss="modal" class="btn"&gt;Close&lt;/button&gt;
                      &lt;button type="button" class="btn yellow"&gt;Ok&lt;/button&gt;*@
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and my second modal (SanayiTipiSecim)</p>
  
  <pre><code>&lt;table class="table-full-width"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Sanayici Tipi&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Açıklama&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="checkbox" name="SANAYI_TIPI" onclick="javascript:sanayitipiTotextarea(1)" id="1" value="Boya Sanayi"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Boya Sanayi
              &lt;/td&gt;
              &lt;td&gt;
                  Boya üretimi yapan imalathaneler
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="checkbox" name="SANAYI_TIPI" onclick="javascript:sanayitipiTotextarea(2)" id="2" value="Enerji üretimi ve dağıtımı"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Enerji üretimi ve dağıtımı
              &lt;/td&gt;
              &lt;td&gt;
                  Ör. Enerji üretim merkezleri, enerji ara istasyonları vb?
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="checkbox" name="SANAYI_TIPI" id="3" onclick="javascript:sanayitipiTotextarea(3)" value="Elektrik ve Elektronik Mühendisliği"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Elektrik ve Elektronik Mühendisliği
              &lt;/td&gt;
              &lt;td&gt;
                  Elektronik parçaların üretimi vb?
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="checkbox" name="SANAYI_TIPI" id="4" onclick="javascript:sanayitipiTotextarea(4)" value="Genel Mühendislik, imalat ve montaj"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Genel Mühendislik, imalat ve montaj
              &lt;/td&gt;
              &lt;td&gt;
                  Herhangi bir mühendislik aktivitesi, üretim veya montaj vb?
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input type="checkbox" name="SANAYI_TIPI" id="5" onclick="javascript:sanayitipiTotextarea(5)" value="Gıda ve içecek"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Gıda ve içecek
              &lt;/td&gt;
              &lt;td&gt;
                  Gıda, alkollü içki vb?
              &lt;/td&gt;
  </code></pre>
  
  <p>script blocks in first page:</p>
  
  <pre><code>&lt;script src="~/Scripts/js/kurulusbilgileri.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      sanayitipleriKaydet = function () {
          debugger
          var data = new Object()
          data.ISIM = $("input[name='ISIM']").val();
          data.ADRES_METIN = $("input[name='ADRES_METIN']").val();
          data.TELEFON = $("input[name='TELEFON']").val();
          data.FAKS = $("input[name='FAKS']").val();
          data.E_POSTA = $("input[name='E_POSTA']").val();
          data.SORUMLU_ISIM = $("input[name='SORUMLU_ISIM']").val();
          data.SORUMLU_SOYISIM = $("input[name='SORUMLU_SOYISIM']").val();
          data.FAALIYET_ALANI = $("input[name='FAALIYET_ALANI']").val();
          data.CEVRE_BILGI = $("input[name='CEVRE_BILGI']").val();
          data.BELEDIYE_MUCAVIR_ALAN = $("input[name='BELEDIYE_MUCAVIR_ALAN']:checked").val();
          debugger
          data.OSB_YERLESIK = $("input[name='OSB_YERLESIK']:checked").val();
          data.KIYI_TESISI = $("input[name='KIYI_TESISI']:checked").val();
          data.VERSIYON = $("input[name='VERSIYON']:checked").val();
          data.SANAYI_TIPI = window.localStorage.getItem("sanayitipiid");
          window.localStorage.removeItem("sanayitipiid");
          debugger
  
          var jsondata = JSON.stringify(data);
          $.ajax({
              type: "POST",
              contentType: 'application/json',
              url: "/KurulusBilgileri/KurulusBilgileriniGuncelle",
              data: jsondata,
              success: function (result) {
                  debugger
                  var jsondata = JSON.parse(result)
                  if (jsondata.Passed) {
                      debugger
                      $('#tdISIM').empty();
                      $('#tdISIM').append(data.ISIM);
                      $('#tdADRES_METIN').empty();
                      $('#tdADRES_METIN').append(jsondata.data.ADRES_METIN);
                      $('#tdTELEFON').empty();
                      $('#tdTELEFON').append(jsondata.data.TELEFON);
                      $('#tdFAKS').empty();
                      $('#tdFAKS').append(jsondata.data.FAKS);
                      $('#tdE_POSTA').empty();
                      $('#tdE_POSTA').append(jsondata.data.E_POSTA);
                      $('#tdSORUMLU_ISIM').empty();
                      $('#tdSORUMLU_ISIM').append(jsondata.data.SORUMLU_ISIM);
                      $('#tdSANAYI_TIPI &gt; #tdtxtSANAYI_TIPI').empty();
                      $('#tdSANAYI_TIPI &gt; #tdtxtSANAYI_TIPI').append(jsondata.data.SANAYI_TIPI);//sanayitipi id si...
                      $('#tdFAALIYET_ALANI &gt; #tdtxtFAALIYET_ALANI').empty();
                      $('#tdFAALIYET_ALANI &gt; #tdtxtFAALIYET_ALANI').append(jsondata.data.FAALIYET_ALANI);
                      $('#tdCEVRE_BILGI &gt; #tdtxtCEVRE_BILGI').empty();
                      $('#tdCEVRE_BILGI &gt; #tdtxtCEVRE_BILGI').append(jsondata.data.CEVRE_BILGI);
                      debugger
  
                      if (jsondata.data.BELEDIYE_MUCAVIR_ALAN == "1") {
                          $("#tdBELEDIYE_MUCAVIR_ALAN &gt; input[name='radioBelediyeMucavirAlan']").prop('checked', true);
                      }
                      else
                          $("#tdBELEDIYE_MUCAVIR_ALAN &gt; input[name='radioBelediyeMucavirAlan']").prop('checked',false);
                      if (jsondata.data.OSB_YERLESIK == "1") {
                          $("#tdOSB_YERLESIK &gt; input[name='radioOsbYerlesik']").prop('checked', true);
                      }
                      else
                          $("#tdOSB_YERLESIK &gt; input[name='radioOsbYerlesik']").prop('checked',false);
                      if (jsondata.data.KIYI_TESISI == "1") {
                          $("#tdKIYI_TESISI &gt; input[name='radioKiyiTesisi']").prop('checked', true);
                      }
                      else
                          $("#tdKIYI_TESISI &gt; input[name='radioKiyiTesisi']").prop('checked',false);
                      if (jsondata.data.VERSIYON == "1") {
                          $("#tdVERSIYON &gt; input[name='radioVersion']").prop('checked', true);
                      }
                      else
                          $("#tdVERSIYON &gt; input[name='radioVersion']").prop('checked',false);
  
                  }
              },
              error: function () {
                  alert("ajax process in error");
              }
          });
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>kurulusbilgileri.js:</p>
  
  <pre><code>$(function () {
      $("#btnSanayiTipiKaydet").on('click', sanayitipleriKaydet)
  });
  
  sanayiTipiTextGetir = function (id)
  {
      var text = $('input[id=' + id + ']').val();
      debugger;
      return text;
  }
  sanayitipilistesinigoster = function () {
      $("#stack2").show();
  }
  
  sanayitipiTotextarea = function (id) {
      $("#divSanayiTipi").show(600, null);
  
      var sanayitipi = $("#" + id).val();
      window.localStorage.setItem("sanayitipiid", id);
  
      $("#input_sanayitipi").val(sanayitipi);
      $("#input_id").val(id);
      $("#stack2").modal('toggle');
  }
  </code></pre>