User Name
Password
AppleNova Forums » Programmer's Nook »

Help me add content with javascript! Please?


Register Members List Calendar Search FAQ Posting Guidelines
Help me add content with javascript! Please?
Thread Tools
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 10:44

So I can do basic stuff with javascript, but one thing I've never been able to get to work is adding content. I want to make a web gallery for pictures and I really like gmail's method when you want to attach files.

Basically it's a link that runs a js and it creates an input type for files. Then there is another link that can you can click and it adds another one…and another…and another as needed. Of course you can remove stuff too, and add others without losing what you've done before. I know this shouldn't be as hard as it is, but I just don't get it.

Anyone care to help? Or if you have a more elegant solution I'd be interested as well. Thanks, this is driving me crazy.
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2005-12-21, 10:48

You're going to want a couple buttons/links and onclick() you're going to want to add/remove input boxes from the DOM.
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 10:53

Ooops, horribly wrong forum. Guess I clicks on the wrong thing
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 10:54

Quote:
Originally Posted by pmazer
You're going to want a couple buttons/links and onclick() you're going to want to add/remove input boxes from the DOM.
Yeah...but HOW? I mean I know onclick() and I use them for other things, but I don't know how to specifically add content to a specific part of the page...even without using onclick and just having it run when the page is loaded.
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2005-12-21, 11:01

How much do you know about editing the DOM with Javascript?
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 11:02

Assume I know nothing.
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2005-12-21, 11:24

The easiest way to do this is probably going to be something like this: http://www.w3schools.com/js/tryit.as...able_insertrow

You're going to want to create a table for the uploads, and add and delete rows from it, and then access those rows to add the file upload box and remove link.

For example, say you have this code:

[PHP]<table id="upload_table"></table>[/PHP]

And you want to add a row and add an upload box to it. The code would look something like:

Code:
var total_upload=0; function addUpload() { var row = document.getElementById('upload_table').insertRow(0); cell = row.insertCell(0); cell.innerHTML('<input type="file" id="upload' + total_upload + '">') total_upload += 1; }
I hope you can see what I'm doing.
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 14:43

Yeah I got it...that paged helped a lot, I got it working. However now I have the question of how do I add it to the end of the table? I will also be working tomorrow on removing rows, but I think I can handle that, if not this thread will be revived
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2005-12-21, 15:14

Table object have an array of rows: http://www.w3schools.com/htmldom/dom_obj_table.asp

So you could accomplish this simply by:

Code:
function addUpload() { var table = document.getElementById('upload_table'); var row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.innerHTML('<input type="file" id="upload[' + table.rows.length + ']">') }
  quote
ast3r3x
25 chars of wasted space.
 
Join Date: May 2004
Send a message via AIM to ast3r3x  
2005-12-21, 17:28

Hmm...that didn't work for me, it still added it to the top.

It works like it is supposed to if I do the length -1...it puts it at the 2nd to last spot, but it doesn't seem to work if it is the last spot. www.swigg.net
  quote
pmazer
Member
 
Join Date: May 2005
Location: Atlanta, GA
Send a message via AIM to pmazer  
2005-12-21, 17:45

Hmm.. that actually works correctly in Gecko-based browsers. I'm guessing it's a bug in Safari.
  quote
Posting Rules Navigation
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

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick ways to add album art to iTunes? ezkcdude Genius Bar 10 2006-07-30 21:37
Final Cut Express - How do I add a good Soft Focus? Gizzer Genius Bar 0 2005-11-28 08:03
Some javascript "point me in the right direction" Wrao Programmer's Nook 8 2005-07-17 09:07
Safari: Controlling movies with javascript ast3r3x Genius Bar 0 2005-04-16 20:14
Does anyone Know how to add Text to idvd productions? zman2005 General Discussion 1 2005-03-19 13:36


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 10:49.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova