www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-07-2009, 05:37 PM
    MiglioreTech MiglioreTech is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 5
    Lightbulb Dynamically Adding Form Elements with JS: Not Submitting

    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>
    you get the point. I also have a hyperlink (<a href='#' onclick='editUser()' >Edit</a>) which sucessfully turns all text values into input type='text', the state to a dropdown, and the image to a file selector, to allow the user to edit this record dynamically. The problem is, when the form is submitted ('user1') only the text input elements values are passed.

    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:
    <?php print_r($_POST); ?>
    I do not see values for the dropdown or newly selected photo. I am using Windows Vista/Firefox. Why would the input type='text' elements be submitted but the <select> and <input type='file'> elements not?

    Thanks!!!
    Reply With Quote
      #2  
    Old 11-08-2009, 03:11 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,142
    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:
    Originally Posted by MiglioreTech
    you get the point
    No, we don't. Not unless you show us the rest of the code.
    Reply With Quote
      #3  
    Old 11-08-2009, 10:28 AM
    MiglioreTech MiglioreTech is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 5
    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!
    Reply With Quote
      #4  
    Old 11-08-2009, 02:47 PM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,142
    I have already answered you. Use DOM methods.
    Reply With Quote
      #5  
    Old 11-08-2009, 05:14 PM
    MiglioreTech MiglioreTech is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 5
    Kor -

    Your technical skills are top notch but your people skills need a "upgrade". Not everyone is as smart as you.
    Reply With Quote
      #6  
    Old 11-09-2009, 04:02 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,142
    Quote:
    Originally Posted by MiglioreTech
    Kor -

    Your technical skills are top notch but your people skills need a "upgrade". Not everyone is as smart as you.
    I never give others the fish. I prefer to give them a rod and let them angle the fish.
    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.
    Reply With Quote
      #7  
    Old 11-09-2009, 10:58 AM
    jamesbcox1980 jamesbcox1980 is offline
    Registered User
     
    Join Date: Dec 2008
    Posts: 243
    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?!?
    Reply With Quote
    Reply

    Bookmarks

    Tags
    adding elements, dynamic forms, javascript


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    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 Off
    HTML code is Off
    Forum Jump


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



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.