You are here: Re: Newb problem with checkboxes « PHP Programming Language « IT news, forums, messages
Re: Newb problem with checkboxes

Posted by Janwillem Borleffs on 07/21/05 00:37

Janwillem Borleffs wrote:
> Or better yet:
>
> document.forms['survey_form'].elements['food_types[]']
>

Or with a minor modification to the JS and the function call only:

<script type="text/javascript">
function checkChoice(obj, first) {
var elements = obj.form.elements[obj.name];
elements[0].checked = obj.checked && first;

if (first) {
for (var i = 1; i < elements.length; i++) {
elements[i].checked = false;
}
}
}
</script>
....
<input type=checkbox name="food_types[]" value="No Preference"
onclick="checkChoice(this, 1)" checked>No Preference:
<br>
<input type=checkbox name="food_types[]" value="Mexican"
onclick="checkChoice(this)"> Mexican:
<br>
<input type=checkbox name="food_types[]" value="Thai"
onclick="checkChoice(this)"> Thai:
<br>
<input type=checkbox name="food_types[]" value="Unlisted Food"
onclick="checkChoice(this)">Unlisted Food


JW

 

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

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