|
|
|
|
![]() ![]() |
Jul 12 2007, 11:28 AM
Post
#1
|
|
|
Super Member Group: [HOSTED] Posts: 796 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:26.78 |
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:
CODE <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 DOM function 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, EDIT: 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. This post has been edited by TavoxPeru: Jul 17 2007, 11:51 PM |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 23rd November 2008 - 12:10 AM |