Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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 9-Nov-12 22:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
DevashishDas at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

define a javascript function for validation as below:
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:
<asp:Button ID="btnSubmit" runat="server" OnClientClick="return Validate();" />
  Permalink  
Comments
DevashishDas at 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 at 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)

  Print Answers RSS
0 Mika Wendelius 236
1 Abhinav S 155
2 Peter Leow 140
3 Kornfeld Eliyahu Peter 115
4 Sergey Alexandrovich Kryukov 115
0 Sergey Alexandrovich Kryukov 8,593
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,456
4 Richard MacCutchan 2,417


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 10 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100