• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

help needed..sigh...

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
erm....first time posting....hehe hi everyone

got a question is there any html or jsp coding to only allow a user to key in value into the group textfield if only the user chooses course 4 in the dropdown box

thxs in advance

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

<form method ="POST" action="AddTraineeDetails.jsp">
<TABLE BORDER=1 WIDTH="400" CELLPADDING=0 CELLSPACING=2>

<TR>
<TD>Course</TD>
<TD>
<select name="course">
<option value="2B">2B
<option value="3">3
<option value="4">4
<option value="4S">4S
<option value="5">5
<option value="Forklift">Forklift
</select>
</TD>
</TR>
<TR>
<TD>Group</TD>
<TD><input type = "text" name = "grp" value ="" size = "2" maxlength = "2"></TD>
</TR>
<TR>
<TD>Frame</TD>
<TD>From <input type = "text" name = "frm" value = "" size = "" maxlength=""> To <input type = "text" name = "to" value = "" size = "" maxlength = ""></TD>
</TR>
</table>
<input type = "submit" value = "Next">


</FORM>
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to figure out what you are asking..

Can I have the text box disabled until 4 options are picked from a list?

Yes you can do that with JavaScript.

Here is an example code:

 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Perry,

Welcome to JavaRanch!

You want the user to be able to enter a value into the Group field only when option 4 is selected in the Group drop-down, right? If I've understood you correctly there are a number of ways to achieve what you want:
  • Only make the group field visible when option 4 is selected. This is generally considered bad practice for UI design - users get confused when fields appear and disappear.
  • Only enable the group field when option 4 is selected (see code example below)
  • Leave things as they are. Because the above options require JavaScript you can't guarantee (on the Internet) that they will work. Users can disable JavaScript in their browsers allowing them to use your form without it. The upshot of this is that your server-side code that handles the submitted values should not assume that there will be no value in the Group parameter just because the submitted value for the Course parameter is not 4.

  • OK, I've taken the unusual step of actually coding something as it's a while since I've done it and I wanted to give it a go. I've adapted your code below to provide the functionality I believe you require (no warranty! ). I also added a change of colour to the disabled field.
    Note that the JavaScript function is defined in the HTML header. Ideally this should be in an external file. The function is called in <body onLoad> to set the field state appropriately when the page first loads and in <select onChange> to set it each time the DDLB selection changes.

    I hope you find this useful.

    Jules

    [ August 29, 2004: Message edited by: Julian Kennedy ]

    [ August 29, 2004: Message edited by: Julian Kennedy ]
    [ August 29, 2004: Message edited by: Julian Kennedy ]
     
    Perry Cheong
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thanks guys my saviours hehe
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic