JQuery :: Custom Form Validator - Adding Span After Input
Nov 2, 2010
I am working with customised form validator..I've this html structure
<div id="tab-perfil"><fieldset>
<legend>Dados Pessoais</legend>
<div class="columns">
<div class="colx3-left-double required">
<label for="nome">Nome</label>
<span class="relative">
<input type="text" name="nome" id="nome" value="" class="full-width">
</span></div>
What I want to do is after the input add a span, I know how to do that, just use insertAfter('#nome'); but I have a class for the ERROR and a class for the OK. This is what I have so far
this.find("#formulario_criar-cliente").submit(function(){
var $inputs = $('#formulario_criar-cliente div .required :input');
$inputs.each(function() {
if ($(this).val() == "") {
$(this).addClass("error");
} else {
$(this).removeClass("error");
}});
return false;
});
When I add the class error I want to show a span with a class="check-error" and when I remove the class I want to show a span with a class="check-ok" but remove the error one. This is for multiple inputs... and I don't know how to achieve that =x
I have created a couple simple custom validators but this one isn't working. I have an input #eSig and two others #FirstName and #LastName. I need to add a rule that says the value of #FirstName must be contained in eSig, and one that is the same for #LastName.
I am attempting to create an ASP.NET Custom Validator javascript for a checkboxlist control. My goal is to limit the total number of selections to be 1 - 5 at most. My problem is that I get a null reference when I attempt to retrieve an object for an individual list item, which of course results in an "object required" error message....
I know the refresh() method is gone since version 1.2 but for somereason even if it's suposed to work without it I can't get it to work.Here's the scenario:I got a select box, depending on the selection I want certain elementto validate so I dynamically add validation class to those elementlike this.$("input#element").toggleClass("{validate:{required:true}}");But when I click submit the element doesn't get validated at all but Ican see the class has been added in firebug.
I'd like to know how to add break tags "<br>" inbetween entry's in an input form, an example is if the word "yada yada" was entered you would wind up with y<br>a<br>d<br>a<br> y<br>a<br>d<br>a
I would like to able to add the break tags with a button onClick. I have no idea where to start ...
Currently on my form if you your input dosn't pass my validation you will see an error message and red box will also appear around the input box. The issue is that if you will it out the box will not disappear until you hit submit. Obviously that is because I have PHP validate the form, but I would like for the red border to go away as soon as the conditions are met, which is why I thought, JS would be the best solution.
I know how to write a conditional state in JS but I am not sure ho to echo out different classes based on the conditions.
how i can put text inside a <input form that disappear when the user clicks inside the form. I would like to write "Description" inside a form so they know that they have to write a description into that form.
I am working with the CUSTOM WIDGET from the DATE PICKER - JQUERY PLUGINI have got everything working fine. The value from the user is now inserted in a <span> element. That's nice, but how do I post that value so I can use it in (like the other form elements) in my form. I rather get it in a textbox. But how do I do that?Below you can see the peace of code that works out the value into a span element. How do I change this so it will be a form (TXT) element.As you noticed I am a Javascript/jQuery beginner.
I am validating my form fields using jquery validate plugin. but itsnot executing my methods. its hitting my validate() method but notactual validation code.I am pasting my code here for your reference.My javascript code:
mysite.validateFormFields = function() { alert('here'); [color=green] [b]// its hitting here [/b][/color]
Here's what I'm trying to do: 1) I get reference to a div that's on my page: var theDiv = $("#" + divID); 2) Now I want to add a custom attribute tag to it, so for instance I want to add "winWidth" so that the div object now contains "winWidth=" for instance. 3) I want to set winWidth now since it's part of theDiv to a value
I'm not sure how to really do 1 + 2. I need to do this on the fly because some javascript logic later will add these attributes dynamically to the div... outside of what the original div had...I don't care what it had, I know I have it now in a JS variable and now I want to both add some new attributes to the div, and then set them on the fly. I don't need these attributes to be on my page, I just need them added to my div variable reference.
I am developing a mobile web app which communicates with a wcf service that returns data in json format. The way security is handled is the user logins and recieves a token which is added to the http header. The login ajax request which passes the url strings to the service is using https protocol. This works fine. The other 2 ajax requests are also supposed to use https but when I do this the custom header isn't added. If I use http which is the old url, the custom header is added to http header. I have tested this using fiddler2 and firebug and for some reason it doesn't like https in the ajax request url.
function login_service() { //$.mobile.pageLoading(); var stringUsername = $('#txtUsername').val(); var stringPassword = $('#txtPassword').val();
Im using the jquery validation plugin: [URL] The forms are generated dynamically using php, with the standard class 'required' the plugin looks for, however when it comes to adding my custom rules i want them to be dynamic, as the name/id attributes are generated based on what the id of the form is: i.e. the form ID is #comp so an input would have a name attribute of comp_forename, comp_surname so basically the validator is initiated by looking in the body for a form: var form_id = $('body form').attr('id'); Then how can icancatante the strings to created the name attributes dynamically in the rules here:
I'm not new to JS, or the web and it's various other technologies, but I ran into a problem. I'm trying to add an event handler for a click on all HTML span tags. Trouble is, getElementByTags() doesn't work and neither does getElementByTagNames(). Strangely, adding an id to the span tags and getting their id's do trigger the handler.
Code: document.getElementsByTagName('span').addEventListener('click',doSomething,false); function doSomething() { alert(this);
Everyone around here sure seems to be doing lots of form validation. Fortunately, I have your solution. I've made a form validator that does LOTS AND LOTS of neat stuff. It's still 'beta' because I'm not done with x-browser 100% etc. Well, you can get all the dope here ....
Trying to make a simple validator for a form i've just created, but for some reason i cant get it to redirect to the pages upon the IF statements being fulfilled.I've got a feeling its because the form seems to still submit the selection...
Using function FrontPage_Form1_Validator(theForm) and added a function to trap a radio optin like
if (theForm.opt_in.value != "yes" || theForm.opt_in.value != "no") { alert("Please make a choice for the "opt_in" field."); theForm.opt_in.focus(); return (false); }
This traps if neither radio has been clicked BUT when I click on OK in the error message box it continues on without having click on a radio button?
Is the action of clicking the OK in the error message setting to True or something? Any idea of a fix?
I'm trying to write a generic/reusable form validator in Javascript... just something that checks to make sure required fields have a value. By generic I mean I don't want to explicitly reference the name/id of the form or the name of any of the data fields within a "validation" function.
if(problemFields.length > 0) { returnval = false; warn(problemFields); /* tells user they're missing a field, that's all */ }
return returnval; }
What I think is happening (not sure) is that the expression form[fieldsToValidate[i]] is not giving me what I want: a reference to the object corresponding to the form field with the same name. In otherwords, I must have some fundamental misunderstanding of how the DOM works here. Unfortunately, I can't seem to find a good enough reference to set me straight....
Im new to jquery so bare over with me :) I have a form, and when the user clicks the submit button, I want jquery to first validate a date field for its format. The format has to be like this: dd-mm-yyyy. So a date of 30-30-3000 would also be valid.
I sometime find it useful to add my own attribute to a HTML tag so that my javascript can access those elements. For instance, new_attribute in the following anchor tag:
When trying to validate this page, however, it doesn't pass. Some of the below questions likely do not make sense, but I hope you get the idea what I am looking for:Is what I am doing bad practice?Is there another way to allow javascript to specifically select just some elements and not others? Should I instead apply multiple classes to the element, and use some of the classes not to modify appearance, but to allow just them to be selected?If using custom attributes, should they somehow be defined so they pass validation?