Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Would like to know the concept behind the working of the URL below:

www.tradeshows.tradeindia.com/musician-expo2013/register.html

If any user clicks on the submit button without filling any information then a javascript pop up appears and all the important fields that has to displayed is shown one by one, I am aware about alert function of javascript but not aware to shown multiple alert messages on single alert if a single or multiple text box is empty.How to achieve this?
Posted

 
Share this answer
 
Comments
webquestionss 12-Nov-12 10:42am    
Hi, It wont work if the user directly clicks on the submit button without filling any information? any other solution regarding javascript?
define a javascript function for validation as below:
JavaScript
function Validate()
{
    var flag = true;
    var msg = "Following validations failed:";

    if(document.getElementByID("txtBox1").value = "")
    {
        flag = false;
        msg += "<br>Enter value for text box 1";
    }
    if(document.getElementByID("txtBox2").value = "")
    {
        flag = false;
        msg += "<br>Enter value for text box 2";
    }

    if (flag = false)
    {
        alert(msg);
        return false;
    }
    else
    {
        return true;
    }
}

set the OnClientClick property of button as this function:
XML
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return Validate();" />
 
Share this answer
 
Comments
webquestionss 10-Nov-12 23:16pm    
Buddy its not working, here's the code that I am using:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function Validate()
{
var flag = true;
var msg = "Following validations failed:";

if(document.getElementByID("txtBox1").value = "")
{
flag = false;
msg += "<br>Enter value for text box 1";
}
if(document.getElementByID("txtBox2").value = "")
{
flag = false;
msg += "<br>Enter value for text box 2";
}

if (flag = false)
{
alert(msg);
return false;
}
else
{
return true;
}
}

</script>

</head>
<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="txtBox1" runat="server">
<br />
<br />
<asp:TextBox ID="txtBox2" runat="server">
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Click" OnClientClick="return Validate();" />
</div>
</form>
</body>
</html>
Gautam Raithatha 11-Nov-12 1:41am    
might be the client ids of textboxes have changed. use <%= control.ClientID %>:

if(document.getElementByID('<%= txtBox1.ClientID %>').value = "")

and

if(document.getElementByID('<%= txtBox2.ClientID %>').value = "")

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