• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

help needed..sigh...  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
    • Quote
    • Report post to moderator
    thanks guys my saviours hehe
     
    Can't .... do .... plaid .... So I did this tiny ad instead:
    ScroogeXHTML - small and flexible RTF to HTML converter library
    https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!