onmouseover change text based on value from database - c#

My code is in C#. I have a span with id change. I need to change the text onmouseover to a value from the database. I got the value and assign it to a label and I made it hidden. Now on mouseover I want to get the value of the hidden label.
Here is my script.
<script>
$(document).ready(function () {
$("#change").mouseover(function () {
$('#change').text("value of label");
});
$("#change").mouseout(function () {
$('#change').text("Investor");
});
});
</script>
How can I do it?
Solved By Me :)
I have solved the issue. It was because I had visible=false in the label properties and I should replace it with style="display:none;" .
.Regarding my Script. It is as below .
$(document).ready(function () {
var originalText = $('#change').text();
$('#change').mouseover(function () {
var hiddenVar = $('[id$="NewAccountsLabel"]').html();
$('#change').text(hiddenVar);
});
$('#change').mouseleave(function () {
$('#change').text(originalText);
});
});

Why don't you use the label value , your label should have the id
$(document).ready(function () {
Var lblvalue = $('#label').val();
$("#change").mouseover(function () {
$('#change').text(lblvalue);
});
$("#change").mouseout(function () {
$('#change').text("Investor");
});

The jQuery events are mouseover and mouseleave events. More on this here
// save the previous value in javascript variable
var originalText = $('#change').text();
//mouse event on mouseover the span
$('#change').mouseover(function() {
// read the value from the hidden label
var hiddenVar = $('#NewAccountsLabel').text();
// assign the new value from the hidden var
$('#change').text(hiddenVar);
});
//mouse event when mouse leaves the span
$('#change').mouseleave(function() {
// assign the original value when it leaves
$('#change').text(originalText);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<span id="change"> Investor</span>
<label id='NewAccountsLabel' hidden> value from DB </label>

Related

ASP.NET Empty Label Text

I am using set value with jquery but i couldn't get value from label
jquery code is here
$(document).ready(function() {
$("input:radio[name=paketler]").click(function () {
var value = $(this).val();
$('#<%=lblradio.ClientID%>').html(value);
});
})
i used hiddenfield,.val(),.text() but i am seeing text value on label but i couldn't get value in codebehind. can you help me ? how can i get value in codebehind.
try :
$('#' +'<%=lblradio.ClientID %>').val(value);
or
$('#<%=lblradio.ClientID %>').val(value);

Issue with setting hidden field in asp.net winforms using jquery

I have some code to set the value of a hidden field so I can access it in the code behind but the value is always empty in the code behind. The value for the effectiveDate is being set but I doesn't look like the hidden field property Value is being set.
<input id="appEffectiveDate" type="text" />
<label id="effectiveDateLabel" for="appEffectiveDate">App Effective Date</label>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<asp:HiddenField ID="appEffectiveDateToSetForUserRole" runat="server" Value="" Visible="false" />
<script>
$(function () {
var SelectedDates = {};
$('#appEffectiveDate').datepicker({
beforeShowDay: function (date) {
var Highlight = SelectedDates[date];
if (Highlight) {
return [true, "Highlighted", Highlight];
}
else {
return [true, '', ''];
}
}
});
$("#effectiveDateLabel").hide();
$("#appEffectiveDate").hide();
$('input[value="85"]').click(function () {
if($(this).is(':checked'))
{
$("#effectiveDateLabel").show();
$("#appEffectiveDate").show();
}
});
$("#appEffectiveDate").change(function () {
var effectiveDate = $("#appEffectiveDate").val();
$(":asp(appEffectiveDateToSetForUserRole)").prop('value', effectiveDate);
});
});
</script>
In the code behind the value is empty for the hidden field:
if (!string.IsNullOrEmpty(appEffectiveDateToSetForUserRole.Value))
{
// this is never called because .Value is empty
}
If Visible is set to false, the control will not be rendered by ASP.NET in the markup at all, which means that jQuery won't be able to find it because it doesn't exist. Just remove the visible=false part. It'll stay hidden.

Grab Gridview textbox input value Jquery

I have built the following Gridview (Employees and their weekly target):
Desired result: I have a submit button at the bottom which will take all the data from the Gridview using jQuery and push it into my database.
At the moment, I cannot even retrieve the textbox values though, i have the following code:
$(document).ready(function () {
$("#btnSubmit").click(function () {
$("#GridView1 td").each(function () {
var value = $(this).text();
alert(value);
});
});
});
This Selects all the "Table Data" cells... It is selecting the names perfectly, but as soon as it gets to a textbox, it doesnt get the value I type in, it just alerts nothing.
I have tried the following too, each with different, but not the desired results:
.html
.val
.innerHTML
Would anyone be able to point out where I am going wrong please? please let me know if you need anymore info...
You have to check if the control exists in the table cells or not
Give this a try
var value = $(this).find('input').length > 0 ? $(this).find('input').val() : $(this).text();
Hope this will work!
You must select the input textbox in your selection as given below
$(document).ready(function () {
$("#btnSubmit").click(function () {
$("#GridView1 td input").each(function () {
var value = $(this).val();
alert(value);
});
});
});

jquery alerts on checked boxes in gridview

Hi I have following code that selects or de selects check boxes in a gridview which works fine.
$(document).ready(function () {
$("#<%=GridView3.ClientID%> input[id*='chkAll']").click(function () {
if ($(this).is(':checked'))
$("#<%=GridView3.ClientID%> input[id*='chkEmployee']").attr('checked', this.checked);
else
$("#<%=GridView3.ClientID%> input[id*='chkEmployee']").attr('checked', false);
});
});
My next step is to use .each class and iterate through each check box and display alert message.
$(document).ready(function () {
$('#mainForm').click(function () {
$("<%=GridView3.ClientID%> input[id*='chkAll']:checked").each(function () {
alert("checked box");
});
});
The above code does not work. Any suggestions how to fix it? Thanks
The second bit of code the selector is missing the #
$(document).ready(function () {
$('#mainForm').click(function () {
$("#<%=GridView3.ClientID%> input[id*='chkAll']:checked").each(function () {
alert("checked box");
});
});

Editorfor checkbox field onclick

I have an editorfor field that is a checkbox and when it is changed from false to true and the form is submitted i need to track that the checkbox was changed and is marked true. Also it has to be a javascript or jquery function.
<div class="editor-field">
#Html.EditorFor(model => model.IsPublic)
</div>
If i need to explain this better please tell me. I just cant think of how else to explain.Thanks
Hope following code will do it:
#Html.HiddenFor(model => model.IsPublicChanged) #*create special model field for handling change event*#
$().ready(function () {
//catch change event and assign value to hidden field
$("input[name=IsPublic]").on("change", function () {
$("input[name=IsPublicChanged]").val('true');
});
});
Or some different js-code if you want to see if value of checkbox was changed comparing to it's initial value:
$().ready(function () {
var trackValue = $("input[name=IsPublic]").prop("checked");
$("form").on("submit", function () {
var actualValue = $("input[name=IsPublic]").prop("checked");
if (actualValue != trackValue) {
$("input[name=IsPublicChanged]").val('true');
}
});
});

Categories