|
HTML <form> POST |
bamccaig
Member #7,536
July 2006
|
I have a form that is largely created using DHTML. I can't show exact code unfortunately, but I can give examples of what is happening... Obviously I haven't mastered the right way to do things yet... I'm still using tables to layout the Web page.
Everything works as expected client-side and all fields exist. I can use the IEDeveloperToolbar to see them and check their values. I can also use JavaScript to see their values on events, for example. I can use Microsoft's Script Debugger to walk the node tree and link the fields to the <form>, which is a parent of the table the tbody is in. When I submit the form, all the fields appear to post except for one. It's a hidden input and I can't explain why it doesn't post... The field exists on the client. Using Microsoft's Script Debugger I have traced it back to the form element (.parentElement.parentElement.parentElement...). I assumed I have the field name wrong, but I switched the HTTP method to GET and went through the variables in the query string and the same field was missing... Does anybody have any guesses why this one field refuses to be sent? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Matthew Leverton
Supreme Loser
January 1999
|
Does it work in a better browser? |
bamccaig
Member #7,536
July 2006
|
Matthew Leverton said: Does it work in a better browser? Good question. [...] Yes. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Matthew Leverton
Supreme Loser
January 1999
|
In that case, I blame IE's DHTML. Try copy/pasting the generated HTML code into a static HTML file and submitting that in IE. If it works, then you know it's a DHTML bug. If it doesn't, you can fiddle with that static HTML file until it works. |
bamccaig
Member #7,536
July 2006
|
I figured out the problem. Now I know why not to use the innerHTML property.
The solution was to instead append a text node. // Append space. o[2].appendChild(document.createTextNode(" ")); // OR if you wrap it like I did... /* * Append space. createSpaceNode() accepts an optional parameter, intCount, to * create a text node with multiple spaces. */ o[2].appendChild(createSpaceNode());
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Matthew Leverton
Supreme Loser
January 1999
|
Quote: Now I know why IE sucks. Corrected. It's usually best to create all input elements with document.createElement(), then set the type before you do anything else. Also, IE has quirks where you must do something like document.createElement('<form enctype="blah">'); if you ever want to set the enctype property, because if you do it after the form is created it won't honor it. |
bamccaig
Member #7,536
July 2006
|
Matthew Leverton said: Also, IE has quirks where you must do something like document.createElement('<form enctype="blah">'); if you ever want to set the enctype property, because if you do it after the form is created it won't honor it. Yeah, the same is true of checkboxes' initial checked property. I found that out the hard way. createCheckboxInput() looks something like... function createCheckboxInput(id, checked, options) { var e = ((navigator.appName == "Microsoft Internet Explorer") ? ("<input" + ((checked) ? (" checked") : ("")) + ">") : ("input")); var o = {checked:checked, id:id, name:id, type:"checkbox"}; if(options != null) o = augment(o, options); return(createElement(e, o)); } In other words,... document.createElement("<input checked>"); // IE document.createElement("input"); // !IE
I'm sure there is a more reliable way to check the browser (and it might help to check the browser version as well, assuming IE8 actually works)... Meh. I haven't tested IE6 yet so I might just need to make more workarounds for it, such as the type property... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Matthew Leverton
Supreme Loser
January 1999
|
That's an evil way... This is better for the times when IE is broken: var e; try { e = document.createElement("<input checked>"); } catch (foo) { e = document.createElement("input"); e.type = "checked"; }
|
bamccaig
Member #7,536
July 2006
|
Matthew Leverton said: That's an evil way... This is better for the times when IE is broken... That certainly looks nicer, but it doesn't account for an unchecked checkbox in IE. I guess this would work... var e; try { checked = (checked ? " checked" : ""); e = document.createElement("<input" + checked + ">"); } catch (foo) { e = document.createElement("input"); e.type = "checked"; } ** EDIT ** That's not working in IE (or I did something wrong)... Technically even createElement is wrapped so my implementation is a little bit different. ** EDIT ** Yeah, I did something wrong. checked and blnChecked are not the same variable. On a side note, I think you meant e.type="checkbox"; and e.checked=checked; -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Matthew Leverton
Supreme Loser
January 1999
|
Quote: On a side note, I think you meant e.type="checkbox"; and e.checked=checked; Yeah, basically in the try goes the minimum that IE requires and in the catch goes the same thing for compliant browsers. Then after you can set the common things. |
bamccaig
Member #7,536
July 2006
|
OK, fixed. Of course, I did something wrong. I was using checked instead of blnChecked. I've been doing something like this...
I said: I haven't tested IE6 yet so I might just need to make more workarounds for it, such as the type property... Actually, it appears to be working in IE6 as well. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|