Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 5, 2008, 07:37 PM   #1
pierce111
macrumors newbie
 
Join Date: Aug 2008
How do I update text in Javascript?

Hi everyone. When I get rid of a object on my webpage with ".removeChild", I am not sure how to update the other text on the page. I should point out that I am creating the objects with the ".createElement" command.

Example of what I mean:
You get ten buttons to delete. They all show you which number button they are. If you delete one button, then the rest update their "button number" so there isn't a "gap in the numbering".


If anyone could help, it would be great!
pierce111 is offline   0 Reply With Quote
Old Sep 5, 2008, 07:46 PM   #2
angelwatt
Demi-God (Moderator emeritus)
 
angelwatt's Avatar
 
Join Date: Aug 2005
Location: Ohio
Well your example isn't very specific. There can be a number of ways to do things depending on the exact HTML you're working with. One thing to look at though is .innerHTML. For instance, if your object was a p tag you could do:

PHP Code:
pObject.innerHTML "New text."
I think this might be what you're trying to get at. If not, give a little more detail on what you're up to.
angelwatt is offline   0 Reply With Quote
Old Sep 5, 2008, 08:23 PM   #3
pierce111
Thread Starter
macrumors newbie
 
Join Date: Aug 2008
Quote:
Originally Posted by angelwatt View Post
Well your example isn't very specific.
Sorry about that. I am rather new to Javascript, so I don't really know how to describe everything yet.

Quote:
Originally Posted by angelwatt View Post
PHP Code:
pObject.innerHTML "New text."
I think this might be what you're trying to get at. If not, give a little more detail on what you're up to.
Unfortunately, I don't think that would work in this instance... Here's some more details:

Step 1: Creates several "DIV" elements with the command: ".createElement"
Step 2: Sets the text inside the "DIV" tag using ".innerHTML" (different for each element"
Step 3: Shows the user the text with a delete button
[What I want to do]
Step 4: User deletes the text and then the other "DIV" tags adjust the change (the ones above goes down by 1 ex. [Testing 31] to [Testing 30])

I hope that's a better explanation.

Last edited by pierce111; Sep 5, 2008 at 09:06 PM.
pierce111 is offline   0 Reply With Quote
Old Sep 6, 2008, 06:35 AM   #4
angelwatt
Demi-God (Moderator emeritus)
 
angelwatt's Avatar
 
Join Date: Aug 2005
Location: Ohio
Yes, that explains it better. It sounds like you already have the code for removing the code so I'll just show you some renumbering code that you hopefully can apply to what you have.

HTML
[HTML]<div id="divs">
<div>1 <input type="button" value="delete" onclick="RenumberDivs()" /></div>
<div>2 <input type="button" value="delete" onclick="RenumberDivs()" /></div>
<div>10 <input type="button" value="delete" onclick="RenumberDivs()" /></div>
</div>[/HTML]
JavaScript
PHP Code:
function RenumberDivs()
{
  var 
divs document.getElementById("divs").getElementsByTagName("div");
  for (var 
x=0y=divs.lengthyx++) {
    
divs[x].innerHTML = (x+1) + " <input type='button' value='delete'"
      
+" onclick='RenumberDivs()' />";
  }

For you, you'll want the "Delete" buttons onclick to call your delete function rather than this renumbering function. Then at the end of your delete function you can call the RenumberDivs function. You'll then have to of course make some edits in the JavaScript when it applies the button and onclick attribute.

Hope this helps.
angelwatt is offline   0 Reply With Quote
Old Sep 6, 2008, 12:35 PM   #5
pierce111
Thread Starter
macrumors newbie
 
Join Date: Aug 2008
Thanks for your help. I had to edit it a little to do what I needed it to do, but now it works great!
pierce111 is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How do I align text in Pages? applefan289 Mac Applications and Mac App Store 4 Feb 20, 2013 03:01 PM
How do you add text/themes in iMovie for Iphone? Khurram iPhone 10 Jun 25, 2010 08:22 AM
how do i make text smaller in safari by default? aleni Mac Basics and Help 2 Oct 10, 2009 06:08 AM
How do you put text on pictures in iMovie? PikiSkymin Mac Applications and Mac App Store 0 Jul 1, 2009 04:23 AM
how do you make text fadein in idvd ? dave12345 Digital Video 6 Dec 19, 2008 08:44 PM


All times are GMT -5. The time now is 11:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC