You are here: Re: HTML Twins « HTML « IT news, forums, messages
Re: HTML Twins

Posted by Jonathan N. Little on 11/29/05 17:04

Sathyaish wrote:
> I am no JavaScript progammer, and unfortunately am having to babysit an
> old code base that has a lot of JavaScript in it.
>
> I have two questions:
>
> (1) Can two HTML controls have the same name? It looks like the obvious
> answer is NO.

The answer is YES. Creating form elements with the same name creates an
array...

a very simple example may demonstrate:

<script type="text/javascript">
function tally(form){
var prices=form.price;
var sum=0;
for(var i=0; i<prices.length; i++){
sum+=parseFloat(prices[i].value);
}
form.subtotal.value=sum;
}
</script>

<form>
1:<input type="text" name="price" value="1.50"><br>
2:<input type="text" name="price" value="2.70"><br>
3:<input type="text" name="price" value="45.00"><br>
4:<input type="text" name="price" value="4.55"><br>
5:<input type="text" name="price" value="2.09"><br>
<hr>
<input type="text" name="subtotal" size"5"><br>
<input type="button" onclick="tally(this.form)" value="Subtotal">
</form>



> (2) What if? What if the developer has given two HTML controls the same
> name, i.e has created the same button more than once with exactly the
> same name and all other attributes? What happens then?
>
> Ok, before you call me lazy, let me tell you, I tried it. Here's what I
> did on a spike solution.
>
>
> <HTML>
>
> <SCRIPT>
> function doFoo()
> {
> document.forms[0].edt.disabled=!document.forms[0].edt.disabled;
> }
> </SCRIPT>
>
> <FORM name="frmFoo">
> <INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
> <INPUT type="button" value="Edit" name="edt" onClick="return doFoo()"/>
> </FORM>
>
> </HTML>
>

They would do the same thing, just like having a duplicate function
buttons say at the top of the page and at the bottom for convenience


<snip>

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация