You must Sign In to post a response.

assigning a value to label from javascript


I am doing a validation using javascript. Checking the field for validation. I want to assign the alert message to a label "user control" which is in the aspx page.

I tried
function check()
var a = document.getElementById('textboxname');
var stra = a.value;
if(stra.length ==0)
document.getElementById('Label1').value = "pls enter the value';


Pls. help me to solve this I am not able to set the value to the labal.



Author: arjun14 Jul 2006 Member Level: Gold   Points : 2


you can assing the values using document.form

To access txtFirstName in your aspx page using JavaScript, use:


To set txtFirstName, use:

document.forms[0]['TestControl:txtFirstName'].value = 'Naveena'

Please refer this URL


Author: Sathish Kumar14 Jul 2006 Member Level: Silver   Points : 2

use the below code to assign a text to the label.

document.getElementById("Label1").innerHTML = "pls enter the value'";

Author: Somesh Bhagat15 Oct 2008 Member Level: Bronze   Points : 2

use the innerHTML property instead of value property.Because labels renderd as a tag and it don't have value property

Author: Fool To Code02 Dec 2008 Member Level: Gold   Points : 2

document.getElementById("Label1").innerText="pls enter value"
document.getElementById("Label1").innerHTML="pls enter value"

Sign In to post your comments