Forum Moderators: open

Message Too Old, No Replies

validate a text array field?

         

gabe8496

5:52 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



I have:
<input type="text" name="string[]" value="">

How can i setup a function to validate this?

I tried something like

function validateShirt(shirt){

if (shirt.string[].value == ""){
alert 'You must specify your custom text';
return false;
};

else return true;
}

What am I missing?

Bernard Marx

5:59 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



shirt['string[]'].value

You can do anything you like within sq brackets.

gabe8496

6:08 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



Thanks!

how would one go about with a function like this;

Verify if text field (string[]) is filled out. if blank, then check box <input type="checkbox" name="nottext"> must be marked.

Bernard Marx

6:13 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Get that other one working properly (because it does!)

Then we'll do this one.
Deal?

gabe8496

6:33 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



yeah...its working. forgot to mention that.

gabe8496

7:07 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



ok, I think i got it. I don't know if this is the right approach but it is working.


if (shirt['string[]'].value == "" && shirt.notext.checked == false) {
alert("If you are not customizing this order, please select No Custom Text");
return false;
};

Bernard Marx

9:13 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks good to me.

You could trim the string (so just a space isn't accepted as a filled entry)
An empty string evaluates to false (as does false, natch), so we could have:
(and it's that pipe again!)

if (!shirt['string[]'].value.replace(/^\s+¦\s+$/g,'') &&!shirt.notext.checked )

..but only if you feel like it.