Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate 1 to 5 in textbox

Status
Not open for further replies.

w11z

Programmer
Mar 26, 2001
40
0
0
CA
Hi Everyone,
I have a form in which the user must enter in a textbox his preferred choice on a scale of 1 to 5. How do I loop through and validate that the user has entered is first 5 choice. Here is part of the form:

<input type="textbox" name="s1q8_1">a. Planning
<input type="textbox" name="s1q8_2">b. Lectures
<input type="textbox" name="s1q8_3">c. Teaching
<input type="textbox" name="s1q8_4">d. Motivation
<input type="textbox" name="s1q8_5">e. Active
<input type="textbox" name="s1q8_6">f. Learning theories
<input type="textbox" name="s1q8_7">g. Learning styles
<input type="textbox" name="s1q8_8">h. Learning discussion

Thank You
 
w11z, is using the textbox absolutely necessary? You might want to consider using radio buttons instead. Something like this will be easier for your users to understand, and you won't have to mess with the problem of preventing your users from entering alpha characters in the text fields and stuff like that:
Code:
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />a. Planning<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />b. Lectures<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />c. Teaching<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />d. Motivation<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />e. Active<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />f. Learning theories<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />g. Learning styles<br />
<input type="radio" name="radio1" />
<input type="radio" name="radio2" />
<input type="radio" name="radio3" />
<input type="radio" name="radio4" />
<input type="radio" name="radio5" />h. Learning discussion<br />

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Thanks for your response Kaht but out of 15 different activities the users have to only choose 5 and place them in order of most important to least important. Example:
a. Planning -> 4
b. Lectures
c. Teaching
d. Motivation -> 2
e. Active -> 5
f. Learning theories -> 1
g. Learning styles
h. Learning discussion -> 3
...
In this example, I have chosent my 5 most important activities (a, d, e, f, h). I have qualified these activities by the most important (1) and the least important (5).

It is necessary that I use textbox...
Any other ideas?

Thank
 
It is necessary that I use textbox...

No, not really. In my example when you are setting which one you thought most important you'd click on the first radio button on that line, that would de-select any other option that you had marked 1 and change it to the one clicked - this would prevent you from having duplicates. You'd have to add in logic to make sure that someone didn't mark the same option as 1, 2, 3, 4, and 5 - but that wouldn't be difficult at all.

With your method you will have to ensure that each number is only typed once in any given box. But then you have to ensure no number above 6 is typed. And then you have to make sure they don't type "abc" in the textfield - or attempt sql injection - and a myriad of other problems that will come along with using text-fields. Radio buttons would really be the best way to do this.

But if you disagree then suit yourself.....

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top