DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

[JavaScript] After Update Event

By: rekha singh | 03 Feb 2010 1:53 pm

Dear all.

I have a option button and text field. I want to to check the option button automatically when someone type any text in text field. That's like After Update Event in Desktop programming.
Thanks.

Best Regards,

 

Comments

That's an onChange handler. Here's some code:

<script type="text/javascri pt">
function ckButton (txtBox) {
txtBox.form. ckbox.checked = true;
}
</script>
...
<input type="text" name="textBox" onChange="ckButton (this);">
...
<input type="checkbox" name="ckbox" >

 

By: rekha singh | 03 Feb 2010

This one reminds me one of my problems:

Is there any technique to check ALL input field's changed status in a form at once? Or must I write an onChange to all field's?

Thanks.
 

By: rekha singh | 03 Feb 2010

What is usually done is the programmer writes onSubmit for the form object. This allows all fields to be validated at once.

 

By: rekha singh | 03 Feb 2010

Thanks very much for the answer. I tried for checkbox and it run well, but for radio type, nothing happen. Here is the script:

<script type="text/javascri pt">
function ckButton (txtBox) {
txtBox.form. radio1.checked = true;
}
</script>
...
<input type="text" name="textBox" onChange="ckButton (this);">
...
<input type="radio" name="radio1" >
Please assist me. Thx

Best Regards,

 

By: rekha singh | 03 Feb 2010

My original problem was that I don't care the new values, I only want to know if the values were changed or not. (should the user click on submit, or he/she can close the page).
 

By: rekha singh | 03 Feb 2010

The problem here is that radio buttons work by having their objects in an array, because all radio buttons that work together have the same  name. Thus, txtBox.form. radio1 refers to an array; in order to refer  to a particular object you need txtBox.form. radio1 [0].

Think of this: you have radio boxes so the user can  select "Yes", "No", or "Maybe". Here's the code:
<input type="radio" name="response" value="Yes"> Yes<br>
<input type="radio" name="response" value="No">No< br>
<input type="radio" name="response" value="Maybe" >Maybe<br>

 

By: rekha singh | 03 Feb 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move