User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Sep 2007
Posts: 1
Reputation: sidmaniac is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sidmaniac sidmaniac is offline Offline
Newbie Poster

Question delete and backspace

  #1  
Sep 24th, 2007
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:

 
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!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 971
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 48
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: delete and backspace

  #2  
Sep 24th, 2007
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.
Plato forgot the nullahedron..
Reply With Quote  
Join Date: Jan 2007
Posts: 2,604
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 119
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: delete and backspace

  #3  
Sep 29th, 2007
Also remember that UNIX variants and VMS define those keys differently.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC