TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-04-2008, 08:11 PM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 24
Thanks: 13
sidisinsane is on a distinguished road
Default Input-field with captured text falsely empties on click

The script captures body-text to a specified input-field by either left-clicking and dragging the mousepointer over or simply performing a double-click on it.

The problem: When text is entered manually into the input-field, it simply disappears when a neighbouring select-element is clicked. Why?

Another minor issue is that I would actually prefer to be able to limit the capturable area to a container with an id.

Although this code doesn't make use of a framework, I wouldn't mind a solution with JQuery or MooTools.

Code:
// Captures highlighted text within the document to a specified input-field.
var text = "";

// Captures all highlighted text.
function captureText() 
{ 
	// Sets text MSIE or Netscape active.
	lookuptext = (document.all) ? document.selection.createRange().text : document.getSelection();
	
	// Form name="research", input name="lookup"
	document.research.lookup.value = lookuptext;

	return TRUE;
}

// Initiate capture function
document.onmouseup = captureText;
if(!document.all) document.captureEvents(Event.MOUSEUP);
sidisinsane is offline  
Reply With Quote
Old 12-04-2008, 11:05 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Its behaviour for me is that when you type something and click, the text you typed in the box disappears. Is this the correct behaviour? I apologise, but I don't really understand, I don't think.
Attached Files
File Type: html Javascript-Test.html (696 Bytes, 178 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-04-2008, 11:37 PM   #3 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 24
Thanks: 13
sidisinsane is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Its behaviour for me is that when you type something and click, the text you typed in the box disappears. Is this the correct behaviour? I apologise, but I don't really understand, I don't think.
Thanks for responding!

I modified your sample-file to demonstrate the behaviour I'm getting and what I'm expecting to get. After testing it, the issues should be clearer.
Attached Files
File Type: html Javascript-Test-2.html (1.3 KB, 168 views)
sidisinsane is offline  
Reply With Quote
Old 12-04-2008, 11:57 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Thanks. I think a simple check to see if you actually selected anything should do it, shouldn't it? By adding in the following code, I seem to have fixed it. Although I'm not entirely if this is the correct behaviour:

javascript Code:
if (!lookuptext)
{
    return;
}
Attached Files
File Type: html Javascript-Test-2.html (1.4 KB, 176 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
sidisinsane (12-05-2008)
Old 12-05-2008, 12:08 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

As for your other problem of only selecting items from a specific DIV, I am unsure. I've never used the createRange() or getSelection() before. I am sorry, but I hope the other thing worked for you!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-05-2008, 12:12 AM   #6 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 24
Thanks: 13
sidisinsane is on a distinguished road
Default

Thanks a lot, Wildhoney. Your fix solves all my issues and so simple it was.
sidisinsane is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh an input field delayedinsanity Javascript, AJAX, E4X 5 07-27-2008 07:48 AM
seeding an input text field with a string joby1 XHTML, HTML, CSS 2 01-03-2008 05:34 PM
PDF Creation - Help! Sam Granger General 7 10-31-2007 11:32 AM


All times are GMT. The time now is 02:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design