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

Enabling Text Box onchange of Combi

Status
Not open for further replies.

mych

Programmer
May 20, 2004
248
GB
Is this possible in standard ASP?

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")
      {
         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
 
Javascript is case sensitive!!

<script type="text/javascript">

function ShowDriverH()
{
if (document.getElementById('JourneyT').value="3")
{
document.getElementById('Dhours').disabled=false
}
}
</script>

Mighty
 
Also you need == in the if statement.
Code:
if (document.getElementById('JourneyT').value=[!]=[/!]"3")

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

Is this possible in standard ASP?

No it's not possible. By the time you are allowed to change the value to 3, all the ASP has already been loaded into your page.



[monkey][snake] <.
 
It is possible... see

I guess. All you did was write HTML with ASP, so basically you are just running a javascript function on an onchange. IMO, you made that code 100 times more complex than it has to be.

When I said it was not possible, I was referring to you trying to run ASP code on an onchange event.



[monkey][snake] <.
 
The events like onChange or onClick or onLoad are all browser events.

Any code that deals with these events must be browser-side code.

ASP is completely unaware of any browser events.

The purpose of ASP is to build a dynamic HTTP Response. From ASP's point of view, it is merely writing data to the Response buffer. IIS then sends this data back to the browser. The browser may interpret this data as HTML, JavaScript, CSS, or whatever but to ASP it is just data.

Chances are that by the time the page even gets across the wire to the browser, the server has completed execution of the ASP and moved on to handling the next Request from another user.

The best you can do is use frames or AJAX to simulate an ASP response to a browser event.
 
Thanks Monksnake and Sheco, your comments are valid and noted. The code I have referenced does what I need and I have had no issues is does set a text box to enabled after a combi box has changed its value. It does despite the fact that the combi and text box concerned are the 6th and 7th oject on a form. I can publish the whole code if anyone is interested. As for complicated I am always interested in keeping things simple so any help in this area would be greatly recieved.

Mych
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top