I have manufacturer name with checkbox, when i checked manufacturer then by checked event i want to display all product from that manufacturer,...
how to achieve CheckBox Checked and Unchecked event in MVC 3
how to achieve CheckBox Checked and Unchecked event in MVC 3
Suppose you have this checkbox:
<input type="checkbox" id="manufacturerCheckbox" />
You can capture it's "Checked and Unchecked event" by:
$("#manufacturerCheckbox").click(function () {
alert($(this).is(':checked')
? 'checkbox is checked'
: 'checkbox is unchecked');
});
Related
I have an MVC2 C# .Net Web App. We are using the built in MVC3 Validation using the Domain class properties [Required(ErrorMessage = "Start From is required.")] and in the HTML #Html.ValidationMessageFor(model => model.StartFrom)
However, when we submit the page using the Cancel button, the validation is fired stating the "Start From is Required" and therefore not exiting the page. How can I disable the Validation on the Cancel button? Or submit the page without firing the Validation?
I think you need to override the default behaviour of the submit button i.e., Cancel button in your case.
Say you have the cancel button like this:
<input type="submit" id="btnCancel" value="cancel"/>
now write the jQuery to override the default behaviour
$(function(){
$('#btnCancel').click(function(e){
e.preventDefault();
//or you can return false from this method.
//return false;
});
});
I found an answer here, on Stackoverflow :) jQuery disable validation
Each of the first two answers in that link worked for me. #Karthik, thanks for the answer. It got me on the right track
Answer 1:
<input id = "theCancel" class="cancel" type="submit" value="Cancel" />
Answer 2:
$(function () {
$('#theCancel').click(function (e) {
$("form").validate().cancelSubmit = true;
});
});
I chose answer 2 and put it in our global js file. All of our Cancel buttons have an id of "theCancel"
How do I reference the submit button? I am trying to set the focus on the submit button when a certain field is exited.
Here's an example of my approach:
dataEvents:[{
type:'blur',
fn: function(){
$('#add').focus();
}
}]
Have also tried $('#submit').focus();
Note: This button is the Add button of the Add New Record modal form of jqGrid
Any help appreciated.
You should be able to set the focus after the blur via a
$('#sData').focus();
Add id in submit button and try this
$(document).ready(function(){
$("#submit").focus();
});
<input type="submit" value="u" name="submit" id="submit"/>
Using KnockoutJS + JQuery Validation, all the control validation is working fine. While Radio btn validation is not working.
Issue 1: * is displayed near to radio btn
Male
Female
output: * Male Expected output : Male *
output: * Female Expected output : Female *
Issue 2: While applying Class=Required both radio buttons are mandatory, how we will resolve the issue
Issue 3: Same thing happend for dynamic radio buttons as well. All are available in the same page.
Guide me......
Try the knockout validation, it works so much nicer together with knockout
https://github.com/ericmbarnard/Knockout-Validation
Make sure your radio buttons have the same "name" attribute (this is the case with jquery validation regardless of using knockout)
You only need to add required class to one of them if you do my first point above
Dynamic radio buttons need to have specific names (and names need to be same for all buttons you want to validate in a group)
For instance, I have this foreach loop that validates the radiobuttons correctly because they have unique names
<input type="radio" data-bind="attr: { name: 'options-' + $index() }" class="required" value="Yes" checked />
<input type="radio" data-bind="attr: { name: 'options-' + $index() }" value="No" checked />
In my view I have this button:
<input type="submit" value="Delete" disabled="disabled" id="btnDelete" name="btnDelete" />
and I have Jquery method which makes it enabled.
This is in the view.
How to check if the button is enabled or disabled in the controller?
I have this method:
public void MyMethod(FormCollection form)
{...}
but form doesn't contain anything about the button.
also, form["btnDelete"] is null.
Yes because input button can not hold any value and returning it is useless.
If you want to have that attribute value in your controller make a hidden input which hold the button value on page load and will be changed on btnDelete click event.
I am trying to use a text box input as a SqlParameter but it only goes into DataSelecting when the page first loads. Not after the from is submitted.
Here is the code on the aspx page.
protected void DataSelecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["#zip"].Value = ZipBox.Text;
}
"
SelectCommand="SELECT Name FROM Names WHERE (ZipCode = #zip)"
OnSelecting="DataSelecting">
SelectParameters>
parameter Name="zip" DefaultValue="1" />
SelectParameters>
SqlDataSource>
FORM
id="ZipSearch" runat="server" action="Default.aspx" method="post">
TextBox ID="ZipBox" runat="server" />
Button id="btnSubmit" Text="Submit" runat="server" />
FORM
Thanks for your help,
Matt
You need to place that code in the button click event. Selecting event is for different purpose.
Old reply (Before OP's comment) :
What do you have in button click event?
The Selecting event would fire before your select command is executed. Hence if your button click event is firing any command, the Selecting event won't be fired.