By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Forms and Divs

P: n/a
Hi,

Can anyone help me with this:

If I have a form as below:

<form name="Show" style="position:absolute;top:200;left:450;backgrou nd-
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;backgrou nd-
color: yellow">
Mouse location.<br>
X: <input type="text" name="MouseX" value="0" size="4"><br>
</div>

Thanks,
Mitch.

Jun 13 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Lee
mi***@bmtmis.demon.co.uk 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;backgrou nd-
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;backgrou nd-
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);
--

Jun 13 '07 #2

P: n/a
Lee wrote:
>
mi***@bmtmis.demon.co.uk 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;backgrou nd-
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;backgrou nd-
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);
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?
Jun 13 '07 #3

P: n/a
Gary Hasler said the following on 6/13/2007 3:22 PM:
Lee wrote:
>mi***@bmtmis.demon.co.uk 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;backgrou nd-
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;backgrou nd-
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);
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 13 '07 #4

P: n/a
Randy Webb wrote:
>
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)?
Jun 14 '07 #5

P: n/a
Gary Hasler wrote:
>
Randy Webb wrote:

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?
Jun 14 '07 #6

P: n/a
On 13 Jun, 16:25, Lee <REM0VElbspamt...@cox.netwrote:
m...@bmtmis.demon.co.uk 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;backgrou nd-
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;backgrou nd-
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);

--

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

Jun 14 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.