|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
All -
What I am doing is nothing novel but for some reason I could not figure it out. I have a table with data: Code:
<table> <tr><td>Name</td><td>Age</td><td>State</td><td>Image</td></tr> <form action='?edit' method='post' enctype="multipart/form-data" id='user1'> <tr><td>John Smith</td><td>20</td><td>NY</td><td><img src='john_smith.jpg'></td></tr></form> </table> I must note that when dynamically creating the input elements, all the text form elements (Name, Age) are set using cell.innerHTML and the dropdown element (state) as well as file (image) are inserted using cell.appendChild. but, upon a PHP Code:
Thanks!!! |
|
#2
|
||||
|
||||
|
innerHTML is not a standard DOM method, thus it does not always insert the elements (or their attributes) into the DOM tree. You should, probably, use the DOM methods to create and append the new elements (createElement(), setAttribute(), appendChild()... and so on). Even so, there are some crossbrowser workarounds, as IE has a bug in creating the name attribute (which attribute is needed for a submit)
Quote:
|
|
#3
|
|||
|
|||
|
Thanks for the reply Kor. So in your opinion, what would be the best way to turn a table filled with values inside of <td>s into input boxes, dropdowns, and other html form elements programmatically with JavaScript?
Thanks! |
|
#4
|
||||
|
||||
|
I have already answered you. Use DOM methods.
|
|
#5
|
|||
|
|||
|
Kor -
Your technical skills are top notch but your people skills need a "upgrade". Not everyone is as smart as you. |
|
#6
|
||||
|
||||
|
Quote:
Here's the rod: DOM objects and methods: http://www.howtocreate.co.uk/tutoria...t/domstructure Creating DOM tables: http://www.howtocreate.co.uk/tutoria...ript/domtables Last edited by Kor; 11-09-2009 at 04:05 AM. |
|
#7
|
|||
|
|||
|
To continue on Kor's post, the only time you should use innerHTML are when you're setting a bottom level tag's text content. IE does not like innerHTML when filling in tables, cells and rows.
Working with createElement can be mundane and time consuming, but is the most appropriate way to add elements in tables.One thing you must keep in mind while working with tables is that some browsers will try to "fix" elements of the table which are missing parts. If you need to add rows and cells to a table, use insertRow() and insertCell() instead of appendChild(), after creating the rows and cells with createElement(). Also, I completely agree with Kor's attitude and method to helping people here. (I have already been through the Kor initiation ) Kor expects you to do some work on your own to find your answer. Although it might seem like a mean thing to do, it will help you in the long run to better understand the concepts you're learning, instead of just being able to solve a single problem.Programming used to be something you got paid to do, and you used to have to pay someone to help you fix a problem or go to school to learn it. So please respect the experts' methods of teaching. If you don't like it, go pay someone to fix your problem and forget about learning programming. It's not that Kor is smarter than any of us (although that may in fact be true); it's the experience. The point is that Kor is trying to give you the tools to teach yourself, since that is what most of us are trying to do. We want to call ourselves self-taught programmers, not forum-taught, right?!? |
![]() |
| Bookmarks |
| Tags |
| adding elements, dynamic forms, javascript |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|