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

onchange event

Status
Not open for further replies.

joyceda59

Technical User
Apr 3, 2007
29
0
0
CA
hi..i am trying to create this form in which there are two fields that i am having troubloe with. what i am trying to do is that as soon as a user changes the value of one field,the value of the second field should be cleared.

I hav a date field and a time field. Originally the date field is set to current date, and time field is set to 'ASAP'. Now, as soon as a user changes the date to a different date, then the time field show get rid of the 'ASAP' value and show a blank value. In order to do this i used this code:


<input type ="text" name ="time" id = "Text3" value = " <% =distTime%> " />

<input type ="text" readonly name = "dateTextField" id = "textField" value = " <% =distDate %> " onchange="form.newRequestForm.time.value == '';" />

 
Well, the problem is that the date field is readonly. So technically it will never change (by that I mean it can never be changed by typing it it). I believe that the onchange event only gets called when a user physically types in it then it loses focus (and only if the text has changed). If you change the value through code, then I believe the onchange will not be called.

(Please note, until someone else confirms this, I could just be completely off my rocker.)

Ron Wheeler
Tekdev Open Source Development
 
ninjadeathmonkey is correct, since the date field is set to readonly the onchange event can never fire because the date cannot be changed.
If you change the value of the date field from code it will not cause the onchange event to fire either, that would only occur if someone manually altered that field and focus was moved elsewhere.

Also, you have one small error in your sample code.
Code:
<input type ="text" readonly name = "dateTextField" id = "textField" value = " <% =distDate %> " onchange="form.newRequestForm.time.value [COLOR=red]=[/color]= '';"     />

Two equal signs are used to compare values. You use only one to assign a value.

At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top