Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In Chrome I am taking label value and assigning to some variable

C#
var other='';
other= document.getElementById("<%=lblother.ClientID %>").value;


after that i am assing this variable value to text box

C#
$('#<%=txtother.ClientID %>').val(other);



But I am getting txtother value as 'undefined'


How to get exact value?
Posted
Updated 6-Jun-13 2:07am
v2
Comments
Thanks7872 6-Jun-13 8:07am    
What do you mean by In Chrome I am taking label value?
AmitGajjar 6-Jun-13 8:10am    
is this working fine in other browsers ?

Try this:

JavaScript
var other = '';

// Get label value
other = $('#<%=lblother.ClientID%>').html();

// Set the textbox value
$('#<%=txtother.ClientID %>').val(other);

// Check the value in the console
console.log($('#<%=txtother.ClientID %>').val());


Hope this helps.
 
Share this answer
 
v2
use .text() instead of value. following is jquery example
JavaScript
var other= $("<%=lblother.ClientID%>").text();
 
Share this answer
 
You are mixing jQuery and native JavaScript. Either stick to document.get...... or use jQuery selector.

In your problem you can do that by using both ways
1) JavaScript way:
JavaScript
var other = document.getElementById("<%=lblother.ClientID %>").value;
document.getElementById("<%=txtother.ClientID %>").value = other;


2) jQuery way:

JavaScript
var other = $("#lblotherClientID").val();
$("#txtotherClientID").val(other);


This is not a rule. Infact it can be done as long as you know what your code is doing, but it is a good practice.
 
Share this answer
 
v2
$('#<%=txtother.ClientID %>').val($('#<%=lblother.ClientID %>').Text());
 
Share this answer
 

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