Jump to content
xisto Community

Problem With Selecting A Textbox Content

Recommended Posts

What i want to do is to first enabled a disabled text box, and then focus and select all the contents of this text box after the user clicks on a checkbox, i have it working with simple HTML and Javascript but how can i do to get the similar result using the DOM??? For simplicity i only include this code that works:

<html><head><script type="text/javascript">function toggle(formname,checkname){var c="CantField"; if(checkname.checked==true) {	checkname.value="on";	document.f[c].disabled=false;	document.f[c].focus();	document.f[c].select();}else {	checkname.value="off";	document.f[c].value="0";	document.f[c].disabled=true;}return;}function init(){document.f.CantField.disabled = true;}// using DOMfunction initD(){document.getElementById('CantField').setAttribute("disabled",true);}function toggleD(formname,checkname){var c="CantField"; if(checkname.checked==true) {	document.getElementById(checkname).setAttribute("value","on");	document.getElementById(c).setAttribute("disabled",false);	document.getElementById(c).focus();	document.getElementById(c).select();}else {	document.getElementById(checkname).setAttribute("value","off");	document.getElementById(c).setAttribute("disabled","true");	document.getElementById(c).setAttribute("value","0");}}</script></head><body onload="init()"><form name="f" action="page.php" method="post" ><input type="checkbox" value="off" name="CheckField" id="CheckField" onclick="toggle('f',this)" /><input type="text" name="CantField" id="CantField" value="0" /><input type="submit" value="Check Out" name="submitCar" /> <input type="button" value="Cancel" name="cancelCar" onclick="java script:this.form.reset();"></form></body></html>

I know that this code must be optimizied but it is only for simplicity because it is a very heavy form.


When I use the toggleD() function the select method dont work, why happens this??? Am I doing something wrong???


Best regards,



Well, i can't find a solution to the DOM problem so i decide to not use it basically because the select() doesn't work in any manner, if someone get the solution please post it.

Edited by TavoxPeru (see edit history)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.