|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ravsta Smarty n00b
Joined: 29 Jul 2005 Posts: 2
|
Posted: Fri Jul 29, 2005 9:28 am Post subject: Looping through smarty generated checkboxes with javascript |
|
|
Hi all, sorry for my newbie-ness.
Ive been looking through the forum but cannot find a solution to my prob as follows:
I have a set of keywords that are generated via smarty code:
Code: |
<form action="<!--[$action_link]-->" method="post" name="deleteKeywords" onSubmit="return checkSelected()" >
<!--[html_checkboxes name="keywords" options=$keywords separator="<br />"]-->
<input type="submit" value="next">
</form> |
they appear and work fine as expected on the front end.
However my problem is need to loop through these checkboxes because I have to check whether at least one of them is checked in order to proceed.
My javascript code is doing the following which incidentally works for smarty radio buttons, but does not work for the checkboxes:
Code: | <script>
function checkSelected()
{
form = document.deleteKeywords;
var keywordSelected;
for (i=0;i<form.keywords.length;i++)
{
if (form.keywords[i].checked)
{
keywordSelected = true;
}
}
if (keywordSelected) {
return true;
} else {
alert("<!--[pnml name=_CHKKEYWORD]-->");
return false;
}
}
</script> |
Any ideas anyone?
Thanks in advance for any response |
|
Back to top |
|
ravsta Smarty n00b
Joined: 29 Jul 2005 Posts: 2
|
Posted: Fri Jul 29, 2005 10:26 am Post subject: |
|
|
did it a bit of manipulating of some other code i found and got a work around but im sure there is an easier way. here is the updated javascript code i used because i could find out how to get the checkboxes names which smarty generates as "keyword[]".
so i did walk through the form elements instead
Code: | <script>
function checkSelected()
{
var theform = document.deleteKeywords, count = 0;
var len = theform.length;
var keywordSelected;
for (count=0; count<len; count++)
{
if (theform[count].type == 'checkbox')
{
if (theform[count].checked)
{
keywordSelected = true;
}
}
}
if (keywordSelected) {
return true;
} else {
alert("<!--[pnml name=_CHKKEYWORD]-->");
return false;
}
}
</script> |
|
|
Back to top |
|
Laurence Smarty Rookie
Joined: 05 Jan 2006 Posts: 7
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|