0

i want to validate login page using java script function. i take one label button for displaying message and two text box for username and password and one button for "Login" .

when user click on "Login" button without enterning username and password then message will be display in label control. So how to check textbox value in javascript function and how to change the value in lblmessage. I call this function in Ok button . I set this function on Button OnClientClick event but this does not work.

1
  • Besides description please post some code. And fix the spelling mistakes too. Commented Nov 20, 2011 at 10:09

4 Answers 4

3

With javascript

A simple example

var lblElement = document.getElementById("yourlabelsid");

lblElement.innerHtml("Your new updated text in the label");

But try to use a javascript libray like jquery, it has a lot of benefits and ease. Generically on jquery, to change the markup of any element, we use

$("#theselector").html("the new markup inside the markup");

In case input elements, we use .val(); $("#mytextbox").val("the value in the textbox");


Based on your description, you want to change the text inside label so a simple example

For this label

<label id="lbl_name">Name:</label>

Use

$("#lbl_name").html("the updated html"); 

Anywhere you need on the script

Sign up to request clarification or add additional context in comments.

Comments

1

It is better to use the asp.net required field validator control instead of making a special javascript function to handle this .. it is simple as setting the control to validate property of the required field validator to the id of the textbox

Comments

1

var msgLabel= document.getElementById('<%=lblMessage.ClientID %>');
msgLabel.innerHTML = "Your message here";

Comments

0
<script language="javascript">

    function check() {
     var a = document.getElementById('<%=label.ClientID%>');
     var b = document.getElementById('<%=textbox.ClientID%>').Value;
     var c = document.getElementById('<%=textbxpassword.ClientID%>').Value;

        if (b  == "" &&  c == "") 
        {
             a.innerHTML = "your text here";
             alert(a.innerHTML);
        }
     }

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.