www.webdeveloper.com
Results 1 to 4 of 4

Thread: Validating 2 text fields with the same NAME

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Validating 2 text fields with the same NAME

    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

  2. #2
    Join Date
    Apr 2003
    Posts
    3
    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!

  3. #3
    Join Date
    Apr 2003
    Posts
    3

    Question

    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

  4. #4
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    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].
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles