monkey_05_06 Posted December 21, 2006 Share Posted December 21, 2006 I, whenever possible, don't like to use JavaScript due to personal preference. However when attempting to retrieve the end-user's browser dimensions I was left with no choice as PHP is completely server-side. One thing that I noticed that actually caused SEVERAL problems for me is JavaScript's registration of HTML forms.Since the only thing I needed to do via JavaScript was retrieve (since this can't be done in PHP) and then post (to transfer the data from JS to PHP) the dimensions, my code was pretty simplistic. My form contained nothing but two elements, one for width, and one for height, both of which were hidden. I didn't need the user to input anything into the form, it was all taken care of by the JavaScript. Or so I thought.In some of my primary testing I realized that without screen output my script wasn't working properly. Well that was simple enough to fix. It was however later when I removed the screen output...then the problems began. I tried everything I could think of to figure out why JavaScript wasn't registering the form (which I determined via JS alerts). All the tutorials I'd read said I was doing nothing wrong...but my form just wasn't being registered!!! WHY ME???So finally I caved in and copied a form from one of the tutorials. It worked exactly as it should have. ARG!!! That's when it occurred to me that this form had textual output as well as visible form elements. What would happen if I tried removing the text and changed the elements to hidden? AHA! JavaScript was no longer registering the form!Simply reinstating the textual output in [i]my[/i] form was enough to get it working again. I figured that others might be able to gain something from this knowledge...but there's also a question here...is this a bug in JavaScript? Or is it by design that "empty"/"non-visible" forms aren't registered? The latter wouldn't really make much sense to me...but I figured it could make for an interesting conversation piece. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 22, 2006 Share Posted December 22, 2006 I don't know what you mean by "JavaScript registering the form". Quote Link to comment Share on other sites More sharing options...
monkey_05_06 Posted December 22, 2006 Author Share Posted December 22, 2006 i.e., the [color=green]document.formname[/color] variable isn't set. So if I have a form like this:[code]<form name = "hiddenForm" action = ""> <input type = "hidden" name = "one" value = "1" /> <input type = "hidden" name = "two" value = "2" /></form>[/code]Then the [color=green]document.hiddenForm[/color] variable won't be set. Changing it to something even as basic as:[code]<form name = "hiddenForm" action = ""> A <input type = "hidden" name = "one" value = "1" /> <input type = "hidden" name = "two" value = "2" /></form>[/code]Will register the variable. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 26, 2006 Share Posted December 26, 2006 Works for me in IE... and you should be pulling it from the .forms collection. Quote Link to comment Share on other sites More sharing options...
monkey_05_06 Posted December 26, 2006 Author Share Posted December 26, 2006 Okay it could just be Firefox 1.5. I don't know if this is any different in FF 2.0. And I'm unfamiliar with "the .forms collection" to which you refer. As I already mentioned, I don't use JS unless it's necessary...and I got it working I just was unsure if this was perhaps a bug. In any case, thanks for the responses. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 27, 2006 Share Posted December 27, 2006 document.formname isn't a valid way of retreiving a form object -- either use getElementById, or document.forms.formname. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.