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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Field Controls

Status
Not open for further replies.

ceeleelewis

Programmer
Sep 26, 2002
45
US
Hello,

I am a newbie to JavaScript. I want to regulate what is entered into a text field box so I can make sure that users are entering the correct information.

Example: (I have a free-form text box named "Colors")

<input type=&quot;textbox&quot; name=&quot;Colors&quot; value=<%rsCrayons%> />

(I want my user to either enter....
&quot;Orange&quot;, &quot;Red&quot; or &quot;Blue&quot;
if the user enters &quot;Pink&quot; as a value than they should receive an error message saying &quot;You can only enter the colors &quot;Orange&quot; &quot;Red&quot; or &quot;Blue&quot;. Please change than re-submit edits.)

It's seems that this should be fairly easy.In psuedo code the expression would look something like this....

document.Color.value=&quot;Orange&quot;, &quot;Red&quot; or &quot;Blue&quot;
if value=&quot;&quot;or &quot;Pink&quot;,&quot;Yellow&quot;,&quot;Gray&quot;,&quot;Black&quot;
then
alert.msgbox&quot;You can only enter the colors &quot;Orange&quot; &quot;Red&quot; or &quot;Blue&quot;. Please change than re-submit edits.&quot;

Am I on the right path here, If not please explain to me my error.
 
If you really want to limit choice, the most user friendly way is a select box. Having said that:

<script>
function checkColor(){
inText = document.myForm.color.value.toLowerCase
switch (inText){
case &quot;orange&quot;:
case &quot;red&quot;:
case &quot;blue&quot;:
//execute your code here
break;
default:
//anything else would end up here
break;
}
}
</script>

<form name=&quot;myForm&quot;>
<input name=color onBlur=&quot;checkColor()&quot;> Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Thanks for the tip. Your tip actually made me think of a different solution. Instead of a select box or free form text box. I just used radio buttons with some VBScript if conditions to keep things simple and user friendly.Eventhough this is the VBScript forum I just want to show my work so the next guy can use it.

<table border=&quot;0&quot; width=&quot;20%&quot; cellspacing=&quot;0&quot; bgcolor=&quot;#FFFFFF&quot; bordercolorlight=&quot;#cccccc&quot; bordercolordark=&quot;#cccccc&quot;>
<tr bgcolor=&quot;#E6E6E6&quot;>

<td bgcolor=&quot;#E6E6E6&quot; width=&quot;75%&quot; nowrap><font face=&quot;Arial&quot; size=&quot;1&quot;>
<tr bgcolor=&quot;#E6E6E6&quot;>
<td>
<%if objRS(&quot;cmdCntrgrp&quot;)=&quot;Adel&quot; then %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Adel&quot; checked />Adel
<% else %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Adel&quot; />Adel
<%end if %>
</td>
<td bgcolor=&quot;#E6E6E6&quot;>
<%if objRS(&quot;cmdCntrgrp&quot;)=&quot;Becky&quot; then %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Becky&quot; checked />Becky
<% else %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Becky&quot; />Becky
<%end if %>
</td>
</tr>

<tr bgcolor=&quot;#E6E6E6&quot;>
<td bgcolor=&quot;#E6E6E6&quot;>
<%if objRS(&quot;cmdCntrgrp&quot;)=&quot;Stacey&quot; then %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Stacey&quot; checked />Stacey
<% else %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Stacey&quot; />Stacey
<%end if %>
</td>
<td bgcolor=&quot;#E6E6E6&quot;>
<%if objRS(&quot;cmdCntrgrp&quot;)=&quot;Stan&quot; then %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Stan&quot; checked />Stan
<% else %>
<input type=&quot;radio&quot; name=&quot;CommandCenterGroup&quot; value=&quot;Stan&quot; />Stan
<%end if %>
</td>
</tr>

</font>
</td>
</tr>
</table>
</td>
</tr>




Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top