I'm trying to find a cross browser solution for editing text in a flickr photo caption manor where the text is displayed in a <div> or <a> tag but changes to a <textarea> via JS when clicked.
There are two problems.
1. setting the focus on the new textarea
2. keeping the new text value when switching back to normal text. Firefox: focuses fine but does not keep the new text value Safari: focuses then instantly looses focus again, and may not keep new text. EI: does not set focus but does keep the new text value.
An example page including js can be seen here: http://macrophotography.com/test.html
Any suggestion or help in figuring out what is happening would be greatly appreciated. I'm a beginner at JS.
Thanks!
Bugboy
Mar 7 '09
25 5200
I'm not sure what you mean.
I have this:
then with JS onclick event i change it to this: - <div><textarea>My text</textarea></div>
i then edit the text: - <div><textarea>My text is edited</textarea></div>
then onblur i remove the textarea and keep my edited text: - <div>My text is edited</div>
i have several div's with text. please see my example at the link above
Thanks!
acoder 16,027
Recognized Expert Moderator MVP
I've not tested what I've suggested, but the idea is simple. If an element with ID "ta1" (the textarea) exists, that means there's one textarea, so remove it and turn it back into text (use parentNode). Once that's done, there's now no element with that ID, so the textarea focus should work.
I think i'm already doing that with the function: - function a_state1()
-
{
-
var p = this.parentNode;
-
p.innerHTML=this.value;
-
a_listener1(p.id);
-
}
The problem arises when the mouse click that blurs the textarea initiating a_state1() ALSO initiates a mousedown event edit_state2() which creates the next texarea. I think that a_state1() is not making the switch before edit_state2() starts ( in FireFox only). Randomly click rows to see the problem, some rows will not drop their texareas.
What i'm looking for is a way to delay edit_state2() until a_state1() has finished the switch. Some type of event order cue that only allows one event to execute at a time then moves a pointer to the next in cue. I swear i've seen this done before for this exact reason but just can remember where...
acoder 16,027
Recognized Expert Moderator MVP
There's two possibilities here along these lines - probably not the most elegant, but should do the job. One is to simply check that the textarea exists in edit_state. If it does, return. You may not want that, so the second option is to use a timeout to repeatedly check that it doesn't exist. If it does, use timeout again, and if it doesn't, execute the code - a sort of polling.
Thanks for all your time, acoder. That seems to be a really simple way of doing it, Thanks!
Bugboy
acoder 16,027
Recognized Expert Moderator MVP
You're welcome. That's what we're here for.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: J Krugman |
last post by:
I need guidance on implementing the following functionality in
JavaScript:
User clicks on a link (or button) in browser window A that brings
up a separate browser popup window B featuring a list/table of 500+
clickable items; clicking on any one of these items causes it (or
rather its label string) to be added to the contents of a textarea
field in the original page A, perhaps after checking that it has
not been added already.
|
by: lawrence |
last post by:
Is this the correct way to test for a method before I use it?
createRange() is, I believe, an IE only method.
function wrapSelectionInTag(selection, tag) {
if (document.selection.createRange) {
var range = document.selection.createRange();
if (range.parentElement() == element) range.text = '<' + tag +
'>' + range.text + '<\/' + tag + '>';
}
|
by: Robert Oschler |
last post by:
I have a textarea element that I have created an onblur() handler for.
In the onblur() handler, I check to make sure that they have saved the
contents of the edit box, before leaving it.
If they have not saved the contents, when they exit the edit box, I put up
an alert telling them to perform the save.
My handler (note: the editBox variable was properly assigned a reference to
the desired HTML textarea element earlier):
|
by: Vinod. |
last post by:
Hi all,
I have added browser control to a windows form. I am loading pages
having multiple frames. I have noticed that the focus in a text is not
maintained when the application is deactivated. I fixed this issue by
finding the active element in dom and then setting its focus. If the
active element is a frameelement then I get the document of the
frameelement and then get the activeelement of that document and set
the focus. This works...
|
by: libsfan01 |
last post by:
hi all!
is it possible to change an element type with javacript for example
onclick to change a text box to a hidden element or to a textarea?
kind regards
marc
| |
by: anil.rita |
last post by:
When the user chooses an AV file to play, based upon the type of file,
I want to use the default installed media player to play it.
I am wondering if this is a good way - any alternatives, suggestions or
improvements?
if( wmv file)
document.write("<OBJECT id=Player
classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 height="354"
width="479">
|
by: Duncan Jones |
last post by:
I'm almost certain there is no easy answer to this question, but I'd
thought I'd just check....
*Ignoring* for a second why I want to do this, is there any way to
specify that an element in a page should ignore all CSS properties
that have been defined for it, and to adopt some form of browser
default?
Suppose I want to add a <tdelement to an *arbitrary* web page. I
want this element to ignore any CSS directives that may already apply
|
by: sufian |
last post by:
I am new to the world of PHP. Below is my simple PHP file "invite.php" with a form having an image send button (I have to use the image send button because it is the requirement, may be this is causing problem!):
<html>
<head><title>Form</title>
</head>
<body>
<script language="javascript" src="validation.js"></script>
<form action="submit.php" method="POST">
<table border ="0" align="center" cellpadding="9"...
|
by: blackrunner |
last post by:
ERROR in my Query?!
ERROR:
Element GESCHLECHT is undefined in FORM.
i think everything ok. Maby somebody can help me here
Element GESCHLECHT is undefined in FORM.
The error occurred in \anmeldung2.cfm: line 404
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |