You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by vishy_sb <sh...@gmail.com> on 2008/11/20 16:28:56 UTC

Check a checkbox when focus on a textbox

Hi all, 

I have a textbox and a checkbox in a form on my web page. I would like to
automatically check the checkbox when the user starts to type something in
the textbox. I believe this can be done by using some javascript. I did some
research over the web and was able to find some code which is shown below.
However I was not able to get it to work.

HTML code:
<input name="containText" TYPE="text" size = "32"
onfocus="checker('contain')" />
<input type = "checkbox" name = "contain" />

Javascript code:
function checker(checkbox) {
var checkBox=document.form.contain; 
checkBox.checked = true;

}


Any help will be greatly appreciated.

Thanks a lot
Cheers,
vishy
-- 
View this message in context: http://www.nabble.com/Check-a-checkbox-when-focus-on-a-textbox-tp20603583p20603583.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Check a checkbox when focus on a textbox

Posted by Swanthe Lindgren <sw...@megasol.se>.
You probably want to call your checker function on the onkeypressed 
event instead of the onfocus event.

But none of this is the "wicket way"!
With wicket you can use an 
AjaxFormComponentUpdatingBehavior("onkeypressed") on the text field 
which updates your model and rerender the checkbox.

//Swanthe

vishy_sb wrote:
> Hi all, 
>
> I have a textbox and a checkbox in a form on my web page. I would like to
> automatically check the checkbox when the user starts to type something in
> the textbox. I believe this can be done by using some javascript. I did some
> research over the web and was able to find some code which is shown below.
> However I was not able to get it to work.
>
> HTML code:
> <input name="containText" TYPE="text" size = "32"
> onfocus="checker('contain')" />
> <input type = "checkbox" name = "contain" />
>
> Javascript code:
> function checker(checkbox) {
> var checkBox=document.form.contain; 
> checkBox.checked = true;
>
> }
>
>
> Any help will be greatly appreciated.
>
> Thanks a lot
> Cheers,
> vishy
>   



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org