Jump to content

Bug(?) with "empty" forms.


monkey_05_06

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.