Click to See Complete Forum and Search --> : Validating 2 text fields with the same NAME


flurbis
04-27-2003, 10:34 PM
I'm trying to verify/validate 2 <TEXTAREA> fields. The data that the user enters for both need to match exactly (and if not, an Alert Box will pop up to notify the user and force them to re-enter their data). Pretty easy...except that the field names for both HAVE to be the same...they feed data into a shopping cart that need the two fields to have the same name. Here are the two fields:

Enter FIRST NAME: <textarea name="0:freeopt" rows=1 cols=10></textarea>
<br>
Enter FIRST NAME: <textarea name="0:freeopt" rows=1 cols=10></textarea>

And now for the JS that I have in place so far--it works perfect validating two text fields with DIFFERENT names, I just need to modify it for 2 with the SAME NAME.

--------------------------------------

function verify_name(element1_name, element2_name){

var fieldalias_name="NAMES you entered did not MATCH. "

var passed_name=false

if (element1_name.value!=element2_name.value){
alert("The "+fieldalias_name+" Please check them again and re-enter.")
element1_name.select()
}

else

passed_name=true

return passed_name

}

--------------------------------------

And here's the <FORM> line...


<FORM action="some_cgi.cgi" method=post onSubmit="return verify_name(this.0:freeopt, this.0:freeopt)">


--------------------------------------

I think using the SPLIT function might be the way to go, but
I don't know how to get the user inputted data into a variable so that I can then use the Split function and put the 2 items into an array...thus allowing me to compare the two.


ANY help would be GREATLY appreciated!

Thanks-

flurbis

flurbis
04-28-2003, 11:28 AM
Sorry for the ignorance Dave, but I don't know what to do with your response. Could you (or anyone else) provide a bit of explanation as to where and how the two lines you wrote should be implemented?

Thanks!

flurbis
04-28-2003, 05:29 PM
Thought I would post the URL to the page that I'm working on...makes more sense when you see it in action.

http://baxter.netgate.net/store/page0.html

The JS on this page DOESN'T work right now. Its what I need to modify in order for it to work.

http://baxter.netgate.net/store/page1.html

The JS on this page DOES work, but in order for it to work, the four TEXTAREA inputs have different names...I need for them all to have the same name.

Any ideas???

Thank you-

flurbis

Charles
04-28-2003, 05:43 PM
1) You're not supposed to give the same name to two different form controls.
2) "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). (http://www.w3.org/TR/html4/types.html#type-name)
3) Forms and form controls are each contained in arrays and can be referenced in JavaScript without using names. The first form on the page is document.forms[0] and the first control in the first form is document.forms[0].elements[0].