Currently I get a count of rows through a small query and I send this result to my main page that is created in asp.net
Currently I'm doing it in these ways and none of them have worked for me.
Form 1
<script type="text/javascript">
$(document).ready(function () {
var lbltext = document.getElementById('lblPlanta').innerHTML;
alert(lbltext);
});
</script>
Form 2
<script type="text/javascript">
$(document).ready(function () {
var lbltext = document.getElementById('lblPlanta').textContent;
alert(lbltext);
});
</script>
Form 3
<script type="text/javascript">
$(document).ready(function () {
value = $("#lblPlanta").text();
alert(value);
});
</script>
Form 4
<script type="text/javascript">
$(document).ready(function () {
value = $("#lblPlanta").val();
alert(value);
});
</script>
Form 5
<script type="text/javascript">
$(document).ready(function () {
var lbltext = document.getElementById('lblPlanta').value;
alert(lbltext);
});
</script>
This is how the Label is created. (In the code the label is above the script)
<label id="lblPlanta"></label>
Initially the label is empty because it is filled automatically, with the result that returns from the database. This result is printed in that label and if it is printed but the problem is that I can not obtain it to assign it to a variable.
Assignment of information to the tag
function getPlantas() {
block();
$.ajax({
url: "../../../pagina/configuracion/empresa/confEmpresa.aspx/getPlanta",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
$("#lblPlanta").html(data.d);
$.unblockUI();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$.unblockUI();
}
});
}
Update
Apparently my problem is that I try to obtain a value before it is loaded through the document.ready, so I replaced it with the following method:
$(window).load(function () {
value = $("#lblPlanta").text();
alert(value);
});
But I still keep the alert blank, someone could mention me some way to make my method run after everything is loaded.