sammySeltzer
asked on
Can someone please show me a sample jquery or regular javascript that can validate a RadioButtonList in Repeater control?
Greetings again,
I have this RadioButtonList control with a Yes or option in Repeater control.
All I am trying to do is to ensure that user chooses either Yes or No before continuing.
I have done a lot RadioButtonList validations but have not found anything that works with Repeater control.
Any ideas experts?
I have this RadioButtonList control with a Yes or option in Repeater control.
Purchased:<asp:radiobuttonlist ID="rblType" runat="server" RepeatDirection="Horizontal" TextAlign="Right" style="display:inline;">
<asp:ListItem Text="New" />
<asp:ListItem Text="Used" />
</asp:RadioButtonList>
All I am trying to do is to ensure that user chooses either Yes or No before continuing.
I have done a lot RadioButtonList validations but have not found anything that works with Repeater control.
Any ideas experts?
ASKER
Hi HainKurt,
Thanks for your response.
It gives me this error:
Warning The use of a keyword for an identifier is invalid
Only thing I have tried so far is regular RadioButtonList validation.
However, I have managed to use the following for disabling and enabling a textbox. I just could not modify it to use for validation that says:
Please choose Yes or No.
Only thing I was able to find online so far.
Would you be able to modify to give me what I am looking for?
Repeater is one control I have had more problems using dropdownlist and radiobuttonlist.
Thanks for your response.
It gives me this error:
Warning The use of a keyword for an identifier is invalid
function rbTypeClick(this)
Only thing I have tried so far is regular RadioButtonList validation.
However, I have managed to use the following for disabling and enabling a textbox. I just could not modify it to use for validation that says:
Please choose Yes or No.
<script type="text/javascript">
$(document).on("click", "input:radio[name$='rblType']", function(){
var selectedItems = $("input:radio[name$='rblType'][value='No']:checked");
$("#textbox1").prop("disabled", selectedItems.length === 0);
});
</script>
Only thing I was able to find online so far.
Would you be able to modify to give me what I am looking for?
Repeater is one control I have had more problems using dropdownlist and radiobuttonlist.
sorry, use
whats the purpose of those buttons?
what will happen if user clicks or dont click?
function rbTypeClick(rb)
whats the purpose of those buttons?
what will happen if user clicks or dont click?
ASKER
Good question.
That's exactly what I am trying to do.
If user does not click on either Yes or No, we want to stop the user from continuing by giving a message to the user that either Yes or No must be selected in other to proceed.
That's exactly what I am trying to do.
If user does not click on either Yes or No, we want to stop the user from continuing by giving a message to the user that either Yes or No must be selected in other to proceed.
If user does not click on either Yes or No, we want to stop the user from continuing by giving a message to the user that either Yes or No must be selected in other to proceed.
so, you dont need to do anything here...
when you continue, check the radio button value. and if it is not checked, stop there...
meantime, use regular radio buttons, or asp radiobuttons for this purpose... if you want to validate this on client...
do you have any test page?
ASKER
Hi,
Not sure of what type of test page you need?
But here is one I hope:
User tries to submit without checking either the Yes button or No button, then an error should be raised.
Something like:
Please choose Yes or No
I was trying to add it to this jquery:
It failed with error that it did not recognize rblType.
This is the harsh reality of Repeater. I am using it here out of need.
Thanks
Not sure of what type of test page you need?
But here is one I hope:
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="repeater_ItemDataBound">
<ItemTemplate>
<table style="width:100%;border: 1px solid black;">
<tr>
<td style="width:50%;border-collapse: collapse;border: 1px solid black;">
Purchased:<asp:radiobuttonlist ID="rblType" runat="server" RepeatDirection="Horizontal" TextAlign="Right" style="display:inline;">
<asp:ListItem Text="Yes" />
<asp:ListItem Text="No" />
</asp:RadioButtonList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
User tries to submit without checking either the Yes button or No button, then an error should be raised.
Something like:
Please choose Yes or No
I was trying to add it to this jquery:
<script type ="text/javascript" >
$(document).ready(function () {
$("#form1").validate({
rules: {
<%=rblType.UniqueID %>: {
required:true,
},
},
messages: {
//This section we need to place our custom validation message for each control.
<%=rblType.UniqueID %>: {
required: "Please choose either Yes or No."
},
},
});
});
</script>
It failed with error that it did not recognize rblType.
This is the harsh reality of Repeater. I am using it here out of need.
Thanks
ok, just use regular radio buttons, give same name and you should be ok... and use those names in your script...
html
css
js
I used
https://jqueryvalidation.org/
demo
https://jsfiddle.net/ey1nu1wh/
* in demo, needs to adjust the message position, I leave it to you, since I am not sure what plugin you use...
html
Purchased:
<input type=radio name=rblType value='N'> New
<input type=radio name=rblType value='U'> Used
css
input[type="radio"] {
margin-left: 30px;
}
js
$("#form1").validate({
rules: {
rblType: {
required: true,
},
},
messages: {
//This section we need to place our custom validation message for each control.
rblType: {
required: "Please choose either Yes or No."
},
},
});
I used
https://jqueryvalidation.org/
demo
https://jsfiddle.net/ey1nu1wh/
* in demo, needs to adjust the message position, I leave it to you, since I am not sure what plugin you use...
ASKER
Well, that worked.
Thanks a bunch for your efforts.
Problem though is that using this regular html radio buttons without the runat="server"
means I can't insert the values into the database; at least I am not aware of that is possible.
Thanks a bunch for your efforts.
Problem though is that using this regular html radio buttons without the runat="server"
<input type=radio name=rblType value='N'> New
<input type=radio name=rblType value='U'> Used
means I can't insert the values into the database; at least I am not aware of that is possible.
yes you can...
on submit, just use Request("rblType")
it will give you N or U
on submit, just use Request("rblType")
it will give you N or U
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much sir.
try this... does it fire every time you click radio?
Open in new window