var countImgscrp = document.getElementById("<%=hiddenScrapBookImgs.ClientID %>").value;
if ((countImgscrp == 10) || (countImgscrp == 20)) {
var retVal = confirm("Do you want to add images in Scrapbook?");
if (retVal == true) {
alert("Click on scrapbook to add images");
return false;
} else {
alert(" form submitted!");
return true;
}
Also - you are checking if a value is true, which will need the '===' operator as opposed to the '==' operator, unless you want to use a string there as well :
if (retVal == true) { ... }
should be :
if (retVal === true) { ... }
Here is a refactored version of your original function :
$("#ctl00_PageContent_btnCreateSub").click(function () {
//Stores the original value
var countImgscrp = document.getElementById("<%=hiddenScrapBookImgs.ClientID %>").value;
//Check if it is 10 or 20
if (countImgscrp == "10") || countImgscrp == "20") {
//Launch Confirm Window
var retVal = confirm("Do you want to add images in Scrapbook?");
//If Confirmed - Prompt to Add Images
if (retVal === true) {
alert("Click on scrapbook to add images");
return false;
//Otherwise Submit the Form
} else {
alert(" form submitted!");
return true;
}
}
});
How are currently determining if a field is required? If you have a specific class or property you could use jQuery to easily check if they all were not empty.
and then add something like this to your Validate function :
var isValid = true;
//Check if all required fields are not empty
$(":input.required").each(function() {
if($(this).val() === ""){
isValid = false;
return;
}
});
Smadhu
Member
509 Points
980 Posts
how to check all required fileds are completed o n submit
Jan 23, 2013 11:55 AM|LINK
how to check all required fileds are completed o n submit
bcoz i want to show other message on button submit....................if all required fields are completed den only i want to show the message
right now when i click on button it checks for required fields and show my message also.............
$("#ctl00_PageContent_btnCreateSub").click(function () {
var countImgscrp = document.getElementById("<%=hiddenScrapBookImgs.ClientID %>").value;
if ((countImgscrp == 10) || (countImgscrp == 20)) {
var retVal = confirm("Do you want to add images in Scrapbook?");
if (retVal == true) {
alert("Click on scrapbook to add images");
return false;
} else {
alert(" form submitted!");
return true;
}
}
});
plz suggets
Rion William...
All-Star
26445 Points
4389 Posts
Re: how to check all required fileds are completed o n submit
Jan 23, 2013 12:31 PM|LINK
This is because you are comparing string values to integer values, which will not yield the correct results :
if (countImgscrp == 10 || countImgscrp == 20) { ... }should be :
if (countImgscrp == "10" || countImgscrp == "20") { ... }Also - you are checking if a value is true, which will need the '===' operator as opposed to the '==' operator, unless you want to use a string there as well :
if (retVal == true) { ... }should be :
if (retVal === true) { ... }Here is a refactored version of your original function :
$("#ctl00_PageContent_btnCreateSub").click(function () { //Stores the original value var countImgscrp = document.getElementById("<%=hiddenScrapBookImgs.ClientID %>").value; //Check if it is 10 or 20 if (countImgscrp == "10") || countImgscrp == "20") { //Launch Confirm Window var retVal = confirm("Do you want to add images in Scrapbook?"); //If Confirmed - Prompt to Add Images if (retVal === true) { alert("Click on scrapbook to add images"); return false; //Otherwise Submit the Form } else { alert(" form submitted!"); return true; } } });Example
Smadhu
Member
509 Points
980 Posts
Re: how to check all required fileds are completed o n submit
Jan 23, 2013 12:41 PM|LINK
ya thats not my issue.........................i dont want to run my other function untill all required fields are completed.
plz suggest
Rion William...
All-Star
26445 Points
4389 Posts
Re: how to check all required fileds are completed o n submit
Jan 23, 2013 01:13 PM|LINK
How are currently determining if a field is required? If you have a specific class or property you could use jQuery to easily check if they all were not empty.
Example :
and then add something like this to your Validate function :
var isValid = true; //Check if all required fields are not empty $(":input.required").each(function() { if($(this).val() === ""){ isValid = false; return; } });Full Example Here
Smadhu
Member
509 Points
980 Posts
Re: how to check all required fileds are completed o n submit
Feb 03, 2013 12:30 PM|LINK
its not only for the input...................required field is for check box also...............
how to check all vrequired fileds are feilds in javascript...............
plz suggets
JammoD
Member
242 Points
49 Posts
Re: how to check all required fileds are completed o n submit
Feb 03, 2013 12:36 PM|LINK
It sounds like what you may be looking for is the "Required Field Validator". I've placed some links below to give you some more information on this.
http://asp.net-tutorials.com/validation/required-field-validator/
http://www.w3schools.com/aspnet/control_reqfieldvalidator.asp
http://msdn.microsoft.com/en-us/library/e78xxk8k(v=vs.71).aspx
Thanks,
Rion William...
All-Star
26445 Points
4389 Posts
Re: how to check all required fileds are completed o n submit
Feb 03, 2013 12:47 PM|LINK
A checkbox is considered an input element, so this would work for both textboxes and checkboxes as well.
Smadhu
Member
509 Points
980 Posts
Re: how to check all required fileds are completed o n submit
Feb 04, 2013 07:17 AM|LINK
sorry above code is not validating my checkbox...............plz find my code below:
<div id="StructureView" runat="server" > <h2 class="lblStructureR">Structure</h2> <asp:Label ID="lbl1" runat="server" Text="Surface we are building on ?"></asp:Label> <div class="divOptions"> <asp:RadioButtonList ID="cblOptionsRadio0" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Selected="True" Value="Grass" >Grass</asp:ListItem> <asp:ListItem Value="SoftSand">Soft Sand</asp:ListItem> <asp:ListItem Value="Compact Sand">Compact Sand</asp:ListItem> <asp:ListItem Value="Interlock"> Interlock</asp:ListItem> </asp:RadioButtonList> </div> <p> <label for="ctl00_PageContent_wrd2" class="W2 W"> How many people do you need to accomodate?</label> <asp:TextBox ID="wrd2" CssClass="TxbBorder" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RFVwrd22" runat="server" ControlToValidate="wrd2" SetFocusOnError="true" ErrorMessage="*"></asp:RequiredFieldValidator> </p> <div> <asp:Label ID="lbl2" runat="server" Text="What set up will be inside the tent ?"></asp:Label> <asp:RadioButtonList ID="cblOptionsRadio1" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="Lounge" Selected="True">Lounge</asp:ListItem> <asp:ListItem Value="Cocktail Reception">Cocktail Reception</asp:ListItem> <asp:ListItem Value="Plated Dinner">Plated Dinner</asp:ListItem> <asp:ListItem Value="Dinner Dance<">Dinner Dance</asp:ListItem> </asp:RadioButtonList> </div> <div> <asp:Label ID="lbl3" runat="server" Text="Can we pin/drill into ground to secure the tent?"></asp:Label> <asp:RadioButtonList ID="cblOptionsRadio2" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Value="Yes" Selected="True">Yes</asp:ListItem> <asp:ListItem Value="No">No</asp:ListItem> </asp:RadioButtonList> </div> <div> <div> </div>