Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Get the script variable(id1) into label(lblcity)

script variable is placed in bellow script file in that i am storing City Name after that City name is bind into label

once check my code and solve the problem

Advance thanks guy's..

What I have tried:

i am trying this way

ASP.NET
<ul class="nav navbar-nav">
							<%--&nbsp; Hyderabad--%>
							<li class=""><a id="popupCity" class="btn btn-sm" data-toggle="modal" data-target="#myModal" href="#"><img class="flag" src="images/india_flag.jpg">&nbsp;<asp:Label ID="lblcity" runat="server"></asp:Label> <span class="sr-only">(current)</span></a></li>
						</ul>


popup code:

HTML
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-body">
      <div class="pops"> 
	 
	  <img src="bkground/india_gate.jpg" class="ind_gate img-responsive" />
	 <div class="choose_city" style="position: absolute; margin-top: -42px; color:#fff;"><h2>Choose your city</h2></div>
      <div class="popb">
	  <div class="header"><h3><img class="flags" src="images/india_flag.jpg">&nbsp; India</h3></div>
	  <hr />
     <div class="col-md-4">
		<p id="city1">Hyderabad</p>
        <p id="city2">Bangolore</p>
        <p id="city3">Chennai</p>
        <p id="city4">Delhi</p>
									
		</div>
      </div>
      </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>



Script code :

HTML
<script>
$(function(){

var appendthis =  ("<div class='modal-overlay js-modal-close'></div>");

	$('a[data-modal-id]').click(function(e) {
		e.preventDefault();
    $("body").append(appendthis);
    $(".modal-overlay").fadeTo(500, 0.7);
    //$(".js-modalbox").fadeIn(500);
		var modalBox = $(this).attr('data-modal-id');
		$('#'+modalBox).fadeIn($(this).data());
	});  
	document.getElementById("popupCity").innerHTML = localStorage.getItem("city")
  $("p").click(function(){
    var cityName = $(this).attr('id');
    var id1 = document.getElementById(cityName).innerHTML;
    console.log(id1);
    document.getElementById("popupCity").innerHTML = id1;
    //document.getElementById("lblcity").innerHTML = id1;

    localStorage.setItem("city", id1);
    location.reload();
    $(".modal-box, .modal-overlay").fadeOut(500, function() {
        $(".modal-overlay").remove();
    });
  })
$(".js-modal-close, .modal-overlay").click(function() {
    $(".modal-box, .modal-overlay").fadeOut(500, function() {
        $(".modal-overlay").remove();
    });
 
});
 
$(window).resize(function() {
    $(".modal-box").css({
        top: ($(window).height() - $(".modal-box").outerHeight()) / 2,
        left: ($(window).width() - $(".modal-box").outerWidth()) / 2
    });
});
 
$(window).resize();
 
});
</script>
Posted
Updated 24-Nov-16 19:09pm
v2

try using clientID
JavaScript
document.getElementById("<%=lblcity.ClientID %>").innerHTML = id1;
 
Share this answer
 
Comments
Member 11652153 24-Nov-16 5:45am    
i am adding document.getElementById("<%=lblcity.ClientID %>").innerHTML = id1;

popup city click not firing
Karthik_Mahalingam 24-Nov-16 9:28am    
which one not working?
button click?
C#
You can add the text in id1 to label this way:
$('#lblcity').text(id1.Tostring());
Tostring() is not mandatory.
 
Share this answer
 
Comments
Member 11652153 24-Nov-16 4:32am    
It is not working
label not get data
Working soution:
$("#<%=lblcity.ClientID %>").text(id1);


Thanks
Happy Coding
 
Share this answer
 
v2
Comments
Member 11652153 24-Nov-16 5:48am    
Not working prashant.

city = lblcity.Text;

in code behind page

it shows empty like lblcity.text="";
Prashant-Systematix 24-Nov-16 6:23am    
Hi what actually you wants to do with value? can you please clear it bit more that on which event you trying to read the value for code behind ?
Instead of
JavaScript
$("p").click(function(){


try below

JavaScript
$('body').on('click', 'p', function() {


When you append the HTML dynamically, events will not be binded to the controls. Hence, you need to bind the events dynamically as above. And try not to mix JavaScript and JQuery. You can write all code in JQuery alone.
You can refer below link
JQuery - On
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900