I'm trying to add a few custom methods to the validator. It doesn't seem to be working properly.
I have an activity drop down. An activity has to be selected. If the value of the activity is 1, 2, or 3 a division and account have to be selected as well. Otherwise those fields can be empty.
I've tried to alert the values in my custom methods but it doesn't seem to fire all the time and even when the value is greater than 3 it doesn't clear the errors if they show up. I guess I'm thinking the validator fires on the value change in each of the fields of the form, but maybe it only fires on the submit function.
Here is the javascript I'm using:
jQuery.validator.addMethod('activitySelected', function (value, element) {
value = parseInt(value.replace(/\s+/g, ''));
return this.optional(element) || value > 0;
}, 'Please select an activity.');
jQuery.validator.addMethod('accountSelected', function (value, element) {
I'm using the $.ajax() function to grab a page and parse it ... but when I do, any styles on the page I pulled are applied to my page. Obviously this isn't what I want, I just want the data to parse. How can I avoid this?
I hope this doesn't come through as a double post, I posted already and it hasn't shown up yet. I have an XML document that is returned which has an element named html. Inside of that element is a block of HTML wrapped with CDATA tags. I can alert the html variable that i create and see it has all of the data inside of it. So I want to parse through and grab certain things now. I'm just trying to get the element to return it's id to me, even though I know it ... because I kept getting the following error. I still continue to get this error with the current code below. Error: Syntax error, unrecognized expression: > Code: $.ajax({ url: "http://www.mysite.com/response.xml", type: "GET", dataType: "xml", success: function (xml) { html = $.trim($(xml).find("html").text()); alert($("#mydiv", html).attr("id")); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("textStatus: " + textStatus); alert("errorThrown: " + errorThrown); } }); XML: <?xml version="1.0" encoding="UTF-8"?> <response> <html><![CDATA[<div id="mydiv">blah blah stuff in here<img src="myimage.png"></div> ]]></html> </response>
I have an XML document that is returned which has an element named html. Inside of that element is a block of HTML wrapped with CDATA tags. I can alert the html variable that i create and see it has all of the data inside of it. So I want to parse through and grab certain things now. I'm just trying to get the element to return it's id to me, even though I know it ... because I kept getting the following error with other code. However I still continue to get this error with the current code below. Error: Syntax error, unrecognized expression: > Code: $.ajax({ url: "http://www.mysite.com/response.xml", type: "GET", dataType: "xml", success: function (xml) { html = $.trim($(xml).find("html").text()); alert($("#mydiv", html).attr("id")); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("textStatus: " + textStatus); alert("errorThrown: " + errorThrown); } }); XML: <?xml version="1.0" encoding="UTF-8"?> <response> <html><![CDATA[<div id="mydiv">blah blah stuff in here<img src="myimage.png"></div> ]]></html> </response>