Greetings mate,
New comer here. Please take it easy on my first post
I have a gridview with a control ID of Gridview1.
Inside this gridview are three textboxes and a checkbox with Id of grid1Details.
Our requirement is as follows:
if checkbox is unchecked and textboxes are empty => You cannot submit your form
if checkbox is checked and textboxes are empty => You can submit your form
if checkbox is unchecked and textboxes are not empty => You can submit your form
Upon page load, by default checkbox is unchecked and all textboxes are enabled.
//markup:
//JS:
When I run the code, if I check the checkbox, it works because it allows user to submit form.
If however, I don't check the checkbox but fill out the textboxes, I keep getting the alert message that Either check the box or enter value in all textboxes.
Any ideas how to modify the javascript to work as expected?
Thanks in advance.
New comer here. Please take it easy on my first post
I have a gridview with a control ID of Gridview1.
Inside this gridview are three textboxes and a checkbox with Id of grid1Details.
Our requirement is as follows:
if checkbox is unchecked and textboxes are empty => You cannot submit your form
if checkbox is checked and textboxes are empty => You can submit your form
if checkbox is unchecked and textboxes are not empty => You can submit your form
Upon page load, by default checkbox is unchecked and all textboxes are enabled.
//markup:
Code:
<td> <asp:Button ID="btnNext" CssClass="btnNext" runat="server" Text="Review Form" OnClientClick="BtnClick();javascript:return ValidateTextBox();" OnClick="btnNext_Click" /></td>
<table>
<tr>
<td>
<asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<headerstyle horizontalalign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtsourcename" CssClass="textClass" placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:250px;" class="form-control"></asp:TextBox><br />
<asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><span style="color:#ff0000">*Check this box if N/A</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceaddress" CssClass="textClass" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox><br /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Income">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtsourceincome" CssClass="textClass" placeholder="Income...(example: 1000)" runat="server" style="width:250px;" class="form-control txtsourceincome numeric"></asp:TextBox><br /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add"
onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();return validate()" /><br /><br /><br>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
CssClass="grvDelButton" OnClientClick="return confirm('are you sure?')" /> <br /><br /><br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
</table>
//JS:
Code:
<script type="text/javascript">
function ValidateTextBox() {
checkbox = document.getElementById("grid1Details");
var textvalue = $(".textClass").attr('value');
if (!checkbox.checked && textvalue != "") {
alert("Either check the box or enter value in all textboxes.");
return false;
}
return true;
}
</script>
When I run the code, if I check the checkbox, it works because it allows user to submit form.
If however, I don't check the checkbox but fill out the textboxes, I keep getting the alert message that Either check the box or enter value in all textboxes.
Any ideas how to modify the javascript to work as expected?
Thanks in advance.