Replacing The InnerHTML Property Efficiently

Jul 19, 2010

While I am an amateur beginner when it comes to JavaScript, I feel that I can at least handle the scripting language to a level which suits my needs, however earlier today a friend asked me if I could lead her to the right direction with a class task of hers. Basically, the project at hand is to create a snippet of JavaScript which, when the user clicks the content of an HTML paragraph element, should replace said paragraph with a <textarea> and allow the user to alter the paragraph's content. Of course the textarea should be accompanied by a save and a cancel button, but seeing as it is a JavaScript class she's taking, the saving shall only be client-sided.

However, the catch is that she will not be allowed to use the innerHTML property.

So, to the question: how would one go (if it is possible, but I highly doubt it isn't) with making something like:

I do feel this could be done in a more smooth looking and operating way by using the contentEditable attribute, but apparently the teacher asked for a textarea.

View 6 Replies


ADVERTISEMENT

InnerHTML Property

Apr 9, 2007

I'm using javascript to dynamically make controls show up or disappear on a form. For some reason, if I load a control (in this case a select control) into the Div it shows up perfectly. If I load text in there, it is fine too. However, if I programmatically try to go from the select control content and cover it with text afterwards, that won't work.

If I change the content from one string to another, it works as well. I just cannot remove a control I've put down and replace it with text or "" or whatever.

View 1 Replies View Related

Netscape 7.0 Memory Leak On Binding Of Div With InnerHTML Property

Mar 13, 2007

I am working with Netscape 7.0 and need to bind a <divwith the
innerHTML property. More specifically, I need to bind a GridView in
the div in question. I am binding the div with some hardcoded data (a
table, which is the HTML equivalent of a GridView). Is there a way
with javascript to dump the memory used by a DOM object (the div that
I am binding with innerHTML)? When i just receive the variable in
javascript, it doesnt seem to leak. I have tried removing and adding
the div each time I bind to it, but it still leaks.

Here is the code:

View 2 Replies View Related

How To Change 10 Image Sources Efficiently

May 14, 2010

I have 10 images on a blank page, all have the exact same source. I want to change all 10 of their sources with javascript to all be one new source(from source1.jpg to source2.jpg in code below). [code]I know I could run a loop and change all 10 of them individually in the loop, but I can't help but think there is a more efficient way. I was thinking of just making them div tags of all the same class and use the image as the background and then using javascript to change the class property. Basically I am asking what you think is the fastest processing time for the user, while also keeping the code very small.

View 2 Replies View Related

How To Efficiently Implement 10 Fckeditors On One Page

Nov 2, 2007

i have 10 textareas that need to be converted in to identical fckeditors (same toolbar, skin and dimensions) right now im repeating the block below 10 times where the just the new FCKeditor ('textareaID') is different. the page weighs in at over 700KB ... fckeditor.html, fckeditor_gecko.js, fckeditor_area.css, etc are all loaded multiple times

im sure there is a better way of implementing this so each of those pages are only loaded once. does anyone know how?

var oFCKeditor = new FCKeditor( 'homeBody' ) ;
oFCKeditor.BasePath = "fckeditor/" ;
oFCKeditor.ToolbarSet = "Basic";
oFCKeditor.Width = 500;
oFCKeditor.Height = 300;
oFCKeditor.ReplaceTextarea() ;

View 1 Replies View Related

JQuery :: Targeting Specific Nested Elements Of $(this) Efficiently?

Nov 24, 2010

My HTML:

<div class="home-button">
<span><a href="#" style="">Button</a></span>
</div>

I have an instance of a div (button), inside this div is a link wrapped in a span. When you hover over the div (".home-button")I want to move the background position inside its "span a", I've achieved this using the code below.

[Code]...

View 1 Replies View Related

Switch Case Detect For Multiple Values More Efficiently?

Sep 7, 2010

I know this does not work, but hopefully you can see what I am trying to do. Only the first value is tested, but I want all of them to be.

[Code]...

Pretend there are like 10 more cases with more numbers with them. Currently this will only text to see if x is 0 or 42. How do I get it to test for the other numbers?

View 7 Replies View Related

Replacing Characters

Mar 6, 2006

I have a script which gathers information from a form and, if needed, writes this info to a 'preview' window. At times {tokens} are used in place of real html tags. How can I tell the script to look for "{" and "}" and replace them, respectively, with "<" and ">".

I tried using "str = str.replace(/{/g, "<").replace(/}/g, ">");" but that didn't work. The script in question is being written by PHP... thus, may be generating a syntax-based failure. Any ideas?

View 14 Replies View Related

Replacing A Table?

Aug 28, 2006

Is it possible to delete a table and put another one in it's place, in the same document?

View 2 Replies View Related

Replacing The Src Of An Img After Loading

Jul 25, 2004

What I want, is the code to look for a particular ID of an img, and then change the filename (but not the whole path) of the image.

For instance...
if the path was "../images/headin.gif", the javascript would find this by the ID, and change to "headin" to "headdown".

I know I can do something like...
if(a.getAttribute("img").indexOf("headin")) {

but then I need to know how to replace "headin" with "headdown".

How can this be done?

(the reason I don't want to replace the whole src, as that would be very simple, is that the path of the image will change depending on the directory the page is in)

View 2 Replies View Related

Replacing Data With DOM

Jul 25, 2005

I'm trying to get my head around DOM and it's usefulness in designing web applications. Some of it is pretty straight forward, while some is kind of vague. What I am trying to do now is write data to a page. I want to fill in the data in the second span below.

<div>  <span>Size</span> <span class="size"></span>  </div>

I can write the data using the following.

var posSize = document.createTextNode(&#398;');  parent.document.getElementById('size').appendChild(posSize);

But as the name suggests, it appends it to the current value. So every time I click something on the page and the value needs to reflect that item, it just appends it to the former value.

View 13 Replies View Related

How To Append Instead Of Replacing

Jan 29, 2007

I got a javascript code that displays new text boxes when someone clicks on a button. Here is the code that goes into the header:

<script type="text/javascript">
boxct=0;
function dispMoreFiles() {
var upbox = "<INPUT name='numbers[]' TYPE='text' size=&#3930;'><br>";
var updiv = document.getElementById("morefiles");
if (boxct<9) {
var addhtml = updiv.innerHTML+upbox;
updiv.innerHTML = addhtml;
boxct++;
} else {
alert('Message');
}}

</script>
I use this simple code in the body to make use of it:

<input type="text" name="numbers[]" size="30">
<div id="morefiles">

<input name="add" type="button" value="Click To Add Another Box">

Now, if I add another box, then type some text into it, then add another box, the box I just typed into is replaced with a new box, and a new box is added. How do I just make it add a new text box instead of replacing a current one?

View 14 Replies View Related

Help For Text Replacing

Apr 19, 2002

I have a pitures folder with this format :

name_setnumber_picnumber.jpg

for ex: foo_1_02.jpg

how to write a function in JS to return the next and prev image names of the given name of the first image. ( foo_1_01.jpg and foo_1_03.jpg ).

View 4 Replies View Related

Replacing A Varying Substring With Itself Plus

Jul 23, 2005

I'd like to globally replace a substring specified by a regular
expression with itself along with some additional characters.
example:

var oldString = 'asdf BRACKETTHISasdfsdf sd asdBRACKETTHISasdf asd'

var newString =
oldString.replace(/sw*BRACKETTHISw*/g, '<' + ?some expression that
accesses current match? + '>' )

And newString winds up as:
'asdf <BRACKETTHISasdfsdf> sd <asdBRACKETTHISasdf>
asd'

Is there a way to do this, or do I have to use other methods?

View 1 Replies View Related

Replacing Href Text

Jan 26, 2006

I have a page that contains several HREFs. Each HREF that I'm interested in has a common parameter (parmX). Does anyone have a script example on how to find-and-replace parmX with parmY?

I'm assuming that I'd need to do this in the onload event - but I don't know much about Javascript.

View 8 Replies View Related

Finding And Replacing A Line

Jun 4, 2006

Say I have some CSS, which is several hundred lines long, with the
contents in this format:

..foo {
blah
color:#000;
blah
}
..bar {
blah
color:#FFF;
}

where the selectors and their opening braces, their closing braces, and
declarations are each on their own lines (always), how can I replace a
specific declaration (line) given a unique selector and a declaration
property. For example, if I wanted the 'color' declaration property line
in the 'bar' class changed.

At the moment I'm iterating through the CSS one line at a time looking
for the selector and then looking for the declaration property (before I
hit the closing brace).

View 1 Replies View Related

Replacing An Onclick Event

Jul 20, 2005

From javascript in IE, I have a need to hijack the onclick event for an element and replace it dynamically with my own.

I have tried the following...

control.onclick = 'myHandler();'

but this doesn't seem to do the trick. How do I go about doing this?

View 3 Replies View Related

JQuery :: Replacing JS Function?

Aug 22, 2009

New to JQuery, but making progress, not sure how to describe this issue, so stay with me. In JS I would build a function that I could call from a variety of actions, including other functions.

eg..
function dosomething(someparam){
// does something.
}
function dothis(){

[Code]...

View 1 Replies View Related

JQuery :: Replacing Text In IE7?

Dec 22, 2010

I try to place user variables in an html page with JQuery. It work with FF, but it do not work with IE7 (and it must work with it...)

[Code]...

View 1 Replies View Related

Replacing Content Of A Div By A Form?

Oct 21, 2010

Code: tr><td><div id="ref">hh</div></td><td>edit button</td> what I want to achieve is that when a user clicks on edit button, first of all hh should be replaced by a text input field and edit button change to update

View 1 Replies View Related

Replacing Images And Memory Use

May 27, 2010

I am developing a simple image editor in an HTA (for a special use-case). Because it is an HTA, it runs in IE only (IE7 to be precise).

Everything is working great so far, however, because I am loading the same img src file over after every edit, I had to attach " + Math.random();" to the image src so that the updated image is displayed.

This has lead to some pretty severe memory issues, as each time I make an edit, it caches another image. Under normal operation, my app uses under 20MB with a single image loaded, however after every edit it adds about 3MB. After a few minutes of testing I have had it consuming over 200MB!

Is there another way to use the same file name, same image src, etc, but have the browser re-read the file before displaying it again rather than using a cached copy.

Alternately, is there a way to make the browser forget about the other copies it has in memory to keep memory usage under control.

View 2 Replies View Related

Replacing Some Content In A Web Page

Jun 15, 2009

I need to replace some content in a web page with new content, without leaving the page.

When opening the following page, there are two rectangles, one being small and the one large: [url]

When clicking the small rectangle in above page, the two rectangles will be replaced by the two in following page: [url]

I understand that the two sets of rectangles may need to be coded in one page. I put them in two different ones in order to present my ideas clearly.

View 4 Replies View Related

IE Replacing Div Content (UPDATED)

Feb 26, 2010

i have a javascript that creates a table then appends it to an empty div. This works fine in FF, however it fails to work in IE8.

[Code]...

View 11 Replies View Related

Replacing A Name With Variable Contents?

Nov 12, 2010

this is simple, but:

function printInput(f){
var ifr = window.frames['printFrame'];
var v1=readCookie('lesson');
if (v1==1){v2='WORKNOTEPAD1'}

[Code]....

How can I make it stop erroring and act as if the "v2" were, say, "WORKNOTEPAD2"?

If the line contains the string it all works fine.

View 15 Replies View Related

Replacing All Occurrences In A String?

Feb 28, 2006

I have a string (erj-23-38h4-230, for instance).

I want to remove all occurrences of the '-'

The replace function only removes the first instance. How can I remove all of them?

View 7 Replies View Related

Replacing Eval() URGENT!

Mar 13, 2006

Im not all to sure what I can do right now. I have a script that I wrote for a userlookup on some website, problem is they have filtered out some key elements, to keep hackers away. Now, heres my problem. How can i make this return the same value, without using eval()

function doc() {
var f = Array (1);
f[0] = 'var d = doc'
f[1] = 'ument;'
eval(f.join(''));
return d;
}

Ive tried many thing, and had no sucess.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved