Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi, I have the following codes, I want to make the Label disappear as according to some condition. For example, if the var result is empty, then I will set the Label's visibility to false, hidden.
Below are my codes,

JavaScript
var result = txtBatch.Text;
if(result.Equals(""))
{
    txtBatch.Visible = false;
    lblBatch.Visible = false;
}
else
{
    txtBatch.Visible = true;
    lblBatch.VIsible = true;
}


But after I try to verify the codes, it prompt me txtBatch not defined error.
The above codes is not written in C# so I dont quite know what the error is, the codes is written in script using Loftware Label Design software. Any help would be appreciated. Urgent. Thank you.
Posted

Hi,

Lets say you have a TextBox like the following:
ASP.NET
<asp:textbox id="txtBatch" runat="Server" text="1234"></asp:textbox>

In javascript do the following to get value:
JavaScript
var result = document.getElementById('<%=txtBatch.ClientID%>').value;

As TextBox is server control, so on runtime this control have different client id
JavaScript
'<%=txtBatch.ClientID%>'
will return control clientid on runtime
Then you can write
if(result.Equals(""))


Hope this helps !! :)

Regards,
Praneet
 
Share this answer
 
v2
Comments
Jamie888 26-Nov-14 22:59pm    
Hi Mr Nadkar, thank you for your suggeestion, but my script above is written in Loftware, can I apply the same script of the above suggestion(which is written in Visual Studio) in Loftware?
From my research, I have come out with a suggestion. Below are my codes/scripts:

JavaScript
if(label.fields.field.(@name == 'SerNumber2').@data.IsNullOrEmpty){
label.fields.field.(@name == 'SerNumber2').@printingField = "false"
}

else
{
label.fields.field.(@name == 'SerNumber2').@printingField = "true"
}


Due to I am writing the codes in Loftware Label Design software, the syntax would be looked as the above. @name and @printingfield are not params that will prompt users to enter some value but they act like data type and visibility respectively. Hope it helps. Thank you.
 
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