Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I have one asp.net page with 50 Text box (asp.net control). I want to create one external JavaScript file with one function like this -->

function validate(str)
{
}

From asp.net page, i want to pass only textbox value to JavaScript. Based on the value(filled or blank), return true or false.

Please help in creating it. Send me the code plz, I need it as soon as possible.

Than You
Posted
Updated 10-Feb-10 7:21am
v3

it's just a simple thing man, code is below.
<script type="text/javascript" src="scripts.js"></script>
In scripts.js file
function validate()
{
      if (document.getElementById("<%=txtfield1.ClientID%>").value=="")
      {
         alert("Field1 can not be empty");
         document.getElementById("<%=txtfield1.ClientID%>").focus();
         return false;
      }
      if (document.getElementById("<%=txtfield2.ClientID%>").value=="")
      {
         alert("Field2 can not be empty");
         document.getElementById("<%=txtfield2.ClientID%>").focus();
         return false;
      }
      .
      .
      .
      .
      .
      .

      if (document.getElementById("<%=txtfield50.ClientID%>").value=="")
      {
         alert("Field50 can not be empty");
         document.getElementById("<%=txtfield50.ClientID%>").focus();
         return false;
      }

      return true;
}
thatraja
 
Share this answer
 
v2
First add an external JavaScript file to the ASPX page:

<script type="text/javascript" src="external_javascript.js"></script>

Then when you want to check for textbox content (filled or empty), just pass its value to the function defined in the external javascript file.

There in the function, you can trim(if spaces are to be avoided) and check the length if it contains any text. Based on it, return true or false.
 
Share this answer
 
i alreay try this thing but it not work if u have small program or application then plz send me

Thank you for ur replay
 
Share this answer
 
U can add the below method in external java script file.

function IsEmptyText(obj, msg, lbl) {
var str = Trim(obj.value);
if (str == "") {
lbl.innerHTML = msg;
obj.focus();
return false;
}

return true;
}

Add reference of JS file on ur page
 
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