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

Enabling TextBox after OnChange of Combi Box 1

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Is this possible?

I have a form with a textbox that only needs to be completed if the combi box before it is changed to a particular value.

What I have done is set the textbox to be disabled at first


Code:
...
<tr valign="top">
   <td align="right"><b>Driver Hours:</b></td>
   <td align="right"><input type="text" id="Dhours" name="Dhours" size="2" disabled="disabled" />hours <i>Min <%= glbstrMinBlockB %> hours<br /> for Block Booking</i></td>
</tr>
...

I also have an function that is triggered OnChange of the combi box


Code:
<script type="text/javascript">

function ShowDriverH()
{
   if (document.getElementById('JourneyT').Value="3")
[red]I've tried (document.getElementById('JourneyT').Value=3) also [/red]
      {
         document.getElementById('Dhours').Disabled=False
      }
}
</script>

What I want to happen is that the textbox 'DHours' will be enabled if the 'JourneyT' combi box changes value to 3

I've been trying alsorts but don't seem to be able to get it to work.

Any help appreciated.
Mych
 
Hi

See thread216-1385133 related to the equality test operator in JavaScript.

Then JavaScript is case sensitive and [tt]value[/tt] and [tt]disabled[/tt] must be in lowercase.

Correct the above then post back with abit more code if you still have problems. ( Feel free to remove the useless HTML markup before posting. Will help us to give answers faster. )

Feherke.
 
Thanks Feherke,

I don't believe it... After getting caught out the first time round in the post you quoted I stuck a post-it to my screen to remind me to use == and not = and then promptly forget about it.

Many Thanks

Mych
 
Hi

Hmm... I did not noticed that was also your question. :)

I think you would enjoy Clipper. There you are free to use either [tt]=[/tt] or [tt]==[/tt] for equality test and [tt]=[/tt] or [tt]:=[/tt] for assignment. :)

Feherke.
 
Ok corrected my silly mistakes but still no joy...

I now have

Code:
[red]This jScript function should enable the DHours textbox is the JourneyT combi = 3[/red]

function EnableDriverH()
{
  if (document.getElementById('JourneyT').value==3)
    {
      document.getElementById('Dhours').disabled=false
    }
}

[red]This vbscript function creates the JourneyT combi dynamically from values in the database[/red]

function DoCombiBox(fTableName, fDisplayField, fValueField, fWhere, fSelectValue, fName, fFirstOption, fOnChange)

'## SQL
   strSQL = "SELECT " & fDisplayField & ", " & fValueField
   strSQL = strSQL & " FROM " & fTableName
   
   If fWhere = "True" then
      strSQL = strSQL & " WHERE Redundant = 0 ORDER BY ID"
   End If

   strSQL = strSQL & ";"

   set rsdrop = my_Conn.execute(strSQL)

   Response.Write "<Select name= '" & fName & "' id = '" & fName & "' onChange= '" & fOnChange &"' >" & vbCrLf
   if rsdrop.EOF or rsdrop.BOF then
      Response.Write "<Option>No Items Found</option>"  & vbCrLf
   else
      if fFirstOption <> "" then
         Response.Write "<option value='0'>&nbsp;"
         Response.Write fFirstOption & "&nbsp;</option>" & vbCrLf
      end if

      do until rsdrop.EOF
         if lcase(rsdrop(fValueField)) = lcase(fSelectValue) then
            Response.Write "<option value='" & rsdrop(fValueField) & "' Selected>&nbsp;"
            Response.Write rsdrop(fDisplayField) & "&nbsp;</option>" & vbCrLf
         else
            Response.Write "<option value='" & rsdrop(fValueField) & "'>&nbsp;"
            Response.Write rsdrop(fDisplayField) & "&nbsp;</option>" & vbCrLf
         end if

         rsdrop.MoveNext
      loop
   end if
Response.Write "</select>"

rsdrop.Close
set rsdrop = nothing

end function

[RED]And this is the section of the asp page that displays the JourneyT combi and the DHours textbox[/red]
<tr valign="top">
   <td align="right"><b>Journey Type:</b></td>
   <td align="right"><% DoCombiBox "tblJourney", "JourneyT", "ID", "True", "", "JourneyT", "Please Select", "EnableDriverH" %></td>
</tr>
<tr valign="top">
   <td align="right"><b>Driver Hours:</b></td>
   <td align="right"><input type="text" id="Dhours" name="Dhours" size="2" disabled="disabled" />hours <i>Min <%= glbstrMinBlockB %> hours<br /> for Block Booking</i></td>
</tr>

I get no errors but when I select 'Block Booking' from the JourneyT combi (value=3) and then try and enter a value in DHours textbox I find it is still disabled.

Any ideas?

Thanks
Mych
 
Hi, try this:
<td align="right"><% DoCombiBox("tblJourney", "JourneyT", "ID", "True", "", "JourneyT", "Please Select", "EnableDriverH()") %></td>

Olav Alexander Mjelde
Admin & Webmaster
 
Thanks Olav,

Putting the brackets in did the job.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top