Trying To Write A Generic Form Validator

Jul 20, 2005

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.

My first shot seems to have some errors in it:

FieldsToValidateByForm = {};
FieldsToValidateByForm['contact'] = ["FirstName",
"LastName","State","Email"];

function validate(form)
{
problemFields = new Array();
returnval = true;
FieldsToValidate = FieldsToValidateByForm[form.id];

for(i=0; i < FieldsToValidate.length; i++) {
fieldInQuestion = form[FieldsToValidate[i]];
if(fieldInQuestion.value.length < 1) //problem spot?
problemFields.push(FieldsToValidate[i]);
}

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....

View 5 Replies


ADVERTISEMENT

Return String And Write Generic Script

Dec 5, 2005

<disclaimer>js newbie</disclaimer>

My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page. Code:

View 18 Replies View Related

Generic Form Validation Script

Aug 24, 2006

I am looking for a generic form validation script for my personal
project. I found few out there in search but nothing too close to what I want.

If I have a form in a page I want to call the javascript valdiation
routine and display all elements error messages in one validation to
their parentNode.

I found few routines which displays error message in alerts and that
too validation for one element at a time.

Can any one point me to open source generic form validations.

View 1 Replies View Related

Using Ultimate Form Validator But Form Is Still Submitting Even Though It Says Which Fields Are Missing

Jun 16, 2010

I am using the ultimate form validator [URL] but the form is still submitting even though it says which fields are missing..

View 2 Replies View Related

Form Validator!

Aug 7, 2002

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 ....

View 2 Replies View Related

Validator For A HTML Form?

Oct 6, 2011

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...

[Code]...

View 1 Replies View Related

Form Validator Question

Mar 29, 2006

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?

View 1 Replies View Related

JQuery :: Validating Form Fields Using Validator Plugin?

May 11, 2009

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]

[code]....

View 3 Replies View Related

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

View 6 Replies View Related

Validate Numbers In A Generic Way?

Apr 9, 2010

In my form, i have around 20 textbox. I want to validate all the textbox. It should accept numbers and decimals. I have the following code...

How can i make the call generic to all the textbox?

View 1 Replies View Related

Generic Parent/Child Communications

May 3, 2006

I have 40 or 50 inputs scattered among many pages that all need the
ability to open a popup which allows the user to navigate a file
directory structure, locate a specific file, and return the fully
qualified file name to the parent window input. All the 40 or 50 inputs
have unique IDs. Given any one input ID, I have everything working
perfectly: the parent form opens the popup using
window.open("FileFinder.aspx?dir=" + UserRootDirectory + "&InPutID=" +
IdCodeInOnClick);

Popup talks back to parent using window.opener.document...

Like I said, give me the input field ID and I can make everything work
every time... but it makes NO sense to write 40 or 50 functions, one
for each unique input field. I tried using

window.opener.document.forms[0].getElementByID(InPutID).value

but I keep getting an error message about something requiring an
object. Is there a way to accomplish this? Also, since I'm new to
JavaScript (and web programming generally), is there a good tool for
debugging JavaScript intended for IE?

View 5 Replies View Related

JQuery :: Extract A Value From Generic Attribute?

Sep 3, 2011

I'm trying to extract a value from an attribute, namely listid in this case, inside an input tag.code...

$list is an associative array fetched from a database. The contents of that array might be irrelevant for the issue. I'm using a jQuery to handle any javascript code. How do I extract $list['id'] from this input tag?

or is there another genius way to accomplish the same other than using an input tag?

View 2 Replies View Related

Create A New Id Based Off Old Ids Using A Generic Type Script?

Nov 9, 2009

ok i have a script which will make a copy of the html in a div and place it into another div the problem with this it creates a duplicate element with the same id so what i want to know is can i create a new id based off old ids using a generic type script

function scope(e)
{
var popin = document.getElementById('popin');

[code]....

View 2 Replies View Related

Generic ClearForm Function When Click CLEAR Button

Jul 23, 2005

I want to write a generic clearForm function to clear the form when
the user click CLEAR button.

Here's my attempts, because I want to take care all html controls. I
think I need to test if the control is submit button, regular button. But I don't know
what I should do on drop down box?

function clearForm()
{var i=0;
for (i=0; i<InputForm.elements.length-1; i++)
{var obj = InputForm.elements[i];
document.write(obj.type); //runtime error: object doesn't support
this property or method
if (obj.type != "submit" && obj.type != "button")
obj.value = "";
}}

View 5 Replies View Related

Creating Generic Javascript Functions (ie. El.onmouseclick = Function ...)

Jan 8, 2007

I want to learn more about creating functions for element events
without having to put onclick event in every tag. For example:

<script>
document.getElementsByTagName('input').onclick = function () {
alert('hello');
}
</script>

Now, I know the above does not work as I have tried it but hopefully
the idea of what I am trying to achieve here. Basically for every input
tag, when the user triggers the event (click) it will do the same
function.

Anyway, I would more so like to learn about this type of scripting
where you assign functions to events. However, I dont know what to
search for in google and the like. Where could I learn more about this?

View 2 Replies View Related

JQuery :: Generic Function To Populate A Dropdown Using JSon?

Jan 5, 2012

I have quite a few calls on my page at different points to populate dropdowns using jSon responses from the server. It is all working fine now apart from one issue. The name of the field that sets the value and text of the new Option(s) being put into the dropdown.

[Code]...

View 2 Replies View Related

Have A Generic Script That Set Input Focus On First Valid Element In A Document?

Jan 19, 2006

Is it possible to have a generic script that set the input focus on the first valid element in a document (not hidden or disabled) ?

This script is at the end of a document, but don't work.

<script type="text/javascript">
document.forms[0].elements[0].focus();
</script>

View 4 Replies View Related

Using URL Variables To Write A Form Field

Feb 16, 2010

Using the url test.html?a=john&b=doe

I am using the following code:

I can't seem to get an alert to show me anything. The eventual result is not an alert, but a document.write to post the url contents to various form fields for firstname= and lastname= etc.

I am really having a hard time using the document.write function, and am not sure how to employ it, whether in the same script statement or in a separate script in the body.

View 22 Replies View Related

Write To Form Element From Popup (js)

Dec 20, 2000

When users goes to my page (main window) and click on a link, it pops up a new window, and that window contains more links.
When users click on the links on the popped up page, i want some text to be added into a textbox on the main window.

so like if the textbox has "Text1"
and when user clicks on that link, the textbox will now have: "Text1 link.."

View 1 Replies View Related

Javascript Write Function Value To Form

Oct 25, 2004

How do you write javascript function value to <input type='hidden' name='example' value='function()'>

View 7 Replies View Related

Use Form Input To Write Cookie For Redirection?

Jul 18, 2010

The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html"

Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc):

<title>Site Title</title>
<script type="text/javascript" src="cookie.js"></script>
<script language="JavaScript" type="text/javascript">
function redirect() {

[Code].....

View 5 Replies View Related

Document.write Into Iframe Changes Charset Of Contained Form To UTF

Jun 2, 2004

I have a window (it's a modal dialog as well, but let's ignore that for now), where I need to write data into an iframe. Dynamically generated data. This data contains a form, this form is then sent to a server process, which expects it to be latin1 (iso-8859-1). It arrives as UTF-8. I have set the charset both in the container html (which contains the iframes) and the iframe in question to latin1, I once toyed with accept-charset of the form as well, all was ignored. So I started to recreate the experiment step by step.

HTML, meta tag text/html charset=iso-8859-1, FORM directly in it --> data is sent as latin1 Next I put the HTML for the form into its own HTML, put an iframe into the first documented and had its src point to the new HTML. Both the new and the old HTML had charset meta tags. Form was loaded into iframe, sent properly as latin1.

I removed both metatags, we're still sending as latin1. Next I thought it might have something to do with the dynamic nature of the iframe filling. I only assigned the iframe's src at runtime. Still, latin1.

Then I took the final step, and instead of reading an html into the src of the iframe, I wrote the code into the iframe with document.write. Everything LOOKED the same, but the server now receives the form data as UTF-8.

For this experiment I am using IE 5.5 (it is our compatibility base, another browser is not an option unfortunately - I'm a straight firefox man at home), and yes, the content has to be written into the iframe dynamically. I cannot create a temp file that I would load into it, or I would much rather not (it's a rather complex performance issue)

To clarify: Soon as I'm using document.write, all meta tags and or accept-charset (or what it was called) for the form are ignored completely.

View 2 Replies View Related

Read And Write A Field Variable / Value Before Form Submission?

Aug 24, 2010

I was wondering if there was a way to dynamically read a field input and respond to it later in the form. My situation is this: I have a question that asks how many workers are employed at a business. Later in the form, the user is asked to add as many workers as they have (section with information on each worker) ..Is there a way I can have something echoed or document.write above the latter section saying "Please add (Number of workers listed above) sections for each worker employed"

View 8 Replies View Related

How To Write Radio Button Form With Dynamic Output

Jan 31, 2011

I am trying to write a radio button form that has dynamic output. If radio 1 selected then the text would say "one", if radio 2 text = "two", etc. For example:
How many chickens do you own?
Radio 1
Radio 2
*Radio 3
Radio 4

I have the following and am stuck, can I stack getElementsbyid...?
Code:
<script type="text/javascript">
function check() {
document.getElementById('Radio1').firstChild.nodeValue='one';
}
<form>
<input type="radio" value="0" id="r1" name="r1" onclick="check()" />
<input type="radio" ???? />
<input type="radio" ???? />
<input type="radio" ???? />
</form>
I own <label for="r1" id="Radio1">blank</label> chickens.

View 3 Replies View Related

JQuery :: Use Document.write Statement To Write Html Tables On Client Side

Jul 27, 2010

I am totally new to jQuery and no good knowledge on javascript. However, I was assigned a task, to convert a javascript program to jQuery due to compatibility problem on browsers like Chrome and Safari. My program originally use javascript xmlDoc.load('....') to read XML file, and then use document.write statement to write html tables on client side. Something like this (the sample below may got lots of syntax problem as I jut want to show the major part):

Code:
document.write('<TABLE >');
var y=x[0].getElementsByTagName('NoOfRows');
for (i=0; i<=noofrows-1 && i<=y.length-1; i++){
document.write(' <TD>');
document.write(z[j].getElementsByTagName('RecordDetails')[0].childNodes[0].nodeValue;
}

Now I changed to use jQuery, I can read the XML file elements. However, when I try to write the table, it failed:

[Code]...

View 1 Replies View Related

Write A Script That Adds An Extra Field To A Form When Needed

Feb 11, 2010

I have been trying to write a script that allows a user to click on a button like a plus sign to add an additional field for a phone number when they have more than one phone number to enter. I have created a script that sort of does this. It doubles up what is already there, so, the first time, everything is fine, but after that I get a lot more fields than I want. I am a php programmer and not familiar enough with javascript to get to what I want. My script is included below. What I am doing here is retrieving the html content and then adding it to what is already there. In php I would use an if conditional test to see if the data has been retrieved.

The first time it would retrieve the data into a variable. After that it would not retrieve it. I think I am getting into some scope and sequence issues here. Javascript is a bit different than php in these regards. Also there is a commented line in the code that asks another question about the use of variables that I don't understand. I also tried using appendChild() here to no avail. I couldn't get that to work at all.

[Code]...

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved