Forum Moderators: open

Message Too Old, No Replies

jQuery validation plug-in 1.7 error when validated

         

toplisek

11:36 am on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have tested the following validation script: jQuery validation plug-in 1.7

1. How to make working validation error as I have to use action=""

Is there possibility as error is not working in this case.

1.

Where is set id="cname" name="name" within validation script?

A simple comment form with submit validation and default messages

Name *

URL demo: [bassistance.de...]

Fotiman

1:48 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure I understand what you're asking. Could you try to elaborate on what you're trying to do and what your question is?

toplisek

2:18 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My validation does not work. I like to define id="cname" name="name" to my changed string like: id="g" name="q"

See enclosed script from URL.

Fotiman

2:40 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Could you post an example form with the script that you have now? I'm not sure what id and name are supposed to be without seeing them in context. Are these query string parameters? Input elements? Attributes on elements?

toplisek

6:53 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. Please download script to validate forms.
2. Please see my form:
<form name="MyForm" action="index.php">
<input type="text" name="q" size="20" />
</form>

You see it has action, name is name="q"
This jQuery validation uses id="cname" name="name"

Where is set this ID and name...

Fotiman

7:13 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok, I'm assuming you're looking at this example:
[docs.jquery.com...]

And that's where you're coming up with cname and name. Those are just the sample values used in the example form. So in the example where they have:

<label for="cname">Name</label>
<em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />


You should create your code as:



<label for="q">Name</label>
<em>*</em><input id="q" name="q" size="20" class="required" minlength="2" />


The example uses a bit of metadata on each element to specify the validation rules, so you might tweak it to suit your own needs.

toplisek

8:29 am on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes I tried this. Issue is I do not find within code cname to change it.

Fotiman

1:56 pm on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you view the source of the example on the page I linked to above, you will see a form containing the following markup:


<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>
<legend>A simple comment form with submit validation and default messages</legend>
<p>
<label for="cname">Name</label>
<em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
</p>
<p>
<label for="cemail">E-Mail</label>
<em>*</em><input id="cemail" name="email" size="25" class="required email" />
</p>
<p>
<label for="curl">URL</label>
<em> </em><input id="curl" name="url" size="25" class="url" value="" />
</p>
<p>
<label for="ccomment">Your comment</label>
<em>*</em><textarea id="ccomment" name="comment" cols="22" class="required"></textarea>
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</fieldset>
</form>


As you can see, that example contains a field with an id "cname" (which is also referenced in the "for" attribute of the label). But this is only an example demonstrating a form with multiple fields to validate. It doesn't matter what the id of the input is.

Are you asking why this example has fields with id values that are variations of the name values? For example name="name" and id="cname"?

toplisek

1:26 pm on Jan 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, why there is variation of names as I do not have <label for="cname">Name</label> but just <input id="" name="" size="25" class="required" minlength="2" />

Fotiman

11:26 pm on Jan 30, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You don't need to use a label field but it's good semantics to use them. Since most form inputs typically have some text label to identify what value is expected in the input, you would place that text within a label element and the "for" field identifies the id of the input field that the label is associated with. So the best option would probably be for you to add a label for the input element, but I don't know what you markup looks like.