Forms and Divs

M

mitch

Hi,

Can anyone help me with this:

If I have a form as below:

<form name="Show" style="position:absolute;top:200;left:450;background-
color: yellow">
Mouse location.<br>
X: <input type="text" name="MouseX" value="0" size="4"><br>
</form>

Then accessing the value of the text box is simple:

alert(document.Show.MouseX.value)

But what if I use a div instead, how can I get at the same value?

<div id="Show" style="position:absolute;top:200;left:450;background-
color: yellow">
Mouse location.<br>
X: <input type="text" name="MouseX" value="0" size="4"><br>
</div>

Thanks,
Mitch.
 
L

Lee

(e-mail address removed) said:
Hi,

Can anyone help me with this:

If I have a form as below:

<form name="Show" style="position:absolute;top:200;left:450;background-
color: yellow">
Mouse location.<br>
X: <input type="text" name="MouseX" value="0" size="4"><br>
</form>

Then accessing the value of the text box is simple:

alert(document.Show.MouseX.value)

But what if I use a div instead, how can I get at the same value?

<div id="Show" style="position:absolute;top:200;left:450;background-
color: yellow">
Mouse location.<br>
X: <input type="text" name="MouseX" value="0" size="4"><br>
</div>

Easy answer: put the form inside the div.
If you don't want to use a form, give the input an "id" attribute
of "MouseX" and use it as in:

alert(document.getElementById("MouseX").value);


--
 
G

Gary Hasler

Lee said:
(e-mail address removed) said:

Easy answer: put the form inside the div.
If you don't want to use a form, give the input an "id" attribute
of "MouseX" and use it as in:

alert(document.getElementById("MouseX").value);
Or, if your form is 'Show' and the control MouseX is inside a div
'ShowDiv', you can still use:
document.forms['Show'].MouseX.value
as the fact the control is inside a Div doesn't affect the
document.forms[] collection, right?
 
R

Randy Webb

Gary Hasler said the following on 6/13/2007 3:22 PM:
Lee said:
(e-mail address removed) said:
Easy answer: put the form inside the div.
If you don't want to use a form, give the input an "id" attribute
of "MouseX" and use it as in:

alert(document.getElementById("MouseX").value);
Or, if your form is 'Show' and the control MouseX is inside a div
'ShowDiv', you can still use:
document.forms['Show'].MouseX.value
as the fact the control is inside a Div doesn't affect the
document.forms[] collection, right?

It would have taken less time to test it than it did for you to post.
Then you would know for sure without having to ask.

P.S. DIV element inside a FORM element. Validate it.
 
G

Gary Hasler

Randy said:
Gary Hasler said the following on 6/13/2007 3:22 PM:
Or, if your form is 'Show' and the control MouseX is inside a div
'ShowDiv', you can still use:
document.forms['Show'].MouseX.value
as the fact the control is inside a Div doesn't affect the
document.forms[] collection, right?

It would have taken less time to test it than it did for you to post.
Then you would know for sure without having to ask.

P.S. DIV element inside a FORM element. Validate it.

I'm sorry, Randy; but you're totally wrong...It took me longer to test
it than to write my original post!

Shows what I know. (Of course it works like a hot damn even if it is
invalid, which is why I've been using it.) What should I be using for a
block element inside a form which contains form elements plus other
stuff (usually text or pictures describing the form input)?
 
G

Gary Hasler

Gary said:
Randy said:
Gary Hasler said the following on 6/13/2007 3:22 PM:
Or, if your form is 'Show' and the control MouseX is inside a div
'ShowDiv', you can still use:
document.forms['Show'].MouseX.value
as the fact the control is inside a Div doesn't affect the
document.forms[] collection, right?

It would have taken less time to test it than it did for you to post.
Then you would know for sure without having to ask.

P.S. DIV element inside a FORM element. Validate it.

I'm sorry, Randy; but you're totally wrong...It took me longer to test
it than to write my original post!

Shows what I know. (Of course it works like a hot damn even if it is
invalid, which is why I've been using it.) What should I be using for a
block element inside a form which contains form elements plus other
stuff (usually text or pictures describing the form input)?

Okay now I'm really confused. Exactly what is not valid about a DIV
inside a FORM?
 
M

mitch

(e-mail address removed) said:











Easy answer: put the form inside the div.
If you don't want to use a form, give the input an "id" attribute
of "MouseX" and use it as in:

alert(document.getElementById("MouseX").value);

--


Thanks to everyone for their posts. That's got me sorted, all woking
now. Thankyou.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top