•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,663 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1567 | Replies: 2
![]() |
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
hi i am trying to implement the delete and back space using javascript,the problem i am facing is whenever i hit the delete button it starts deleting from the end instead of the current cursor position and continues like backspace after that till the end. the code for delete is below:
code for bank space:
can anyone please help me to achieve my goal of implementing the back space and delete in the true sense!!
thank you!!
case "btnDel": // ID of button
{
try
{
var temp="";
if (document.getElementById("txtSearch").value.length>0)
{
document.getElementById("txtSearch").value=document.getElementById("txtSearch").value.substring(0,document.getElementById("txtSearch").value.length-1);
}
}code for bank space:
case "btnBackSpace":
{
try
{
var temp="";
if (document.getElementById("txtSearch").value.length>0)
{
document.getElementById("txtSearch").value=document.getElementById("txtSearch").value.substring(0,document.getElementById("txtSearch").value.length-1);
}can anyone please help me to achieve my goal of implementing the back space and delete in the true sense!!
thank you!!
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation:
Rep Power: 5
Solved Threads: 48
Er.. yeah. Use the sure-fire, well tested, unecessary to even implement behaviour of a standard input element.
If you MUST reimplement the behaviour of an input yourself, reimplement it entirely, and don't use the standard input as a base; in that way, you can easily control and query the cursor position yourself, and then you know where to start deleting from. Hard work? relatively.
If you MUST use the standard input and you MUST use your own code to do backspace/delete, you'll need to use crazy code like this:
http://weetbixthecat.com/blog/2006/g...n-in-an-input/
to get hold of the current position of the cursor. It's crazy because, in internet explorer, you need to calculate a content length offset from the beggining of the page to the beggining of the input, in order to work out exactly where the cursor is relative to the input itself. Then, you can use that offset to determine from where to start removing text.
If you MUST reimplement the behaviour of an input yourself, reimplement it entirely, and don't use the standard input as a base; in that way, you can easily control and query the cursor position yourself, and then you know where to start deleting from. Hard work? relatively.
If you MUST use the standard input and you MUST use your own code to do backspace/delete, you'll need to use crazy code like this:
http://weetbixthecat.com/blog/2006/g...n-in-an-input/
to get hold of the current position of the cursor. It's crazy because, in internet explorer, you need to calculate a content length offset from the beggining of the page to the beggining of the input, in order to work out exactly where the cursor is relative to the input itself. Then, you can use that offset to determine from where to start removing text.
Plato forgot the nullahedron..
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Sony Vaio - help!!!! (Troubleshooting Dead Machines)
- can't delete single chars in a string (C)
- newbee here (Community Introductions)
- cannot delete shortcut (Windows 9x / Me)
- Can't delete a folder (Windows NT / 2000 / XP / 2003)
- CSRSS Backspace Bug in Windows NT 4/NT 2000/NT XP (Windows NT / 2000 / XP / 2003)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Changing a stylesheet on the fly and saving it with PHP
- Next Thread: java Script Problem



Linear Mode