Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Looping through smarty generated checkboxes with javascript

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
ravsta
Smarty n00b


Joined: 29 Jul 2005
Posts: 2

PostPosted: Fri Jul 29, 2005 9:28 am    Post subject: Looping through smarty generated checkboxes with javascript Reply with quote

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? Rolling Eyes

Thanks in advance for any response Smile
Back to top
View user's profile Send private message
ravsta
Smarty n00b


Joined: 29 Jul 2005
Posts: 2

PostPosted: Fri Jul 29, 2005 10:26 am    Post subject: Reply with quote

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 Embarassed

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
View user's profile Send private message
Laurence
Smarty Rookie


Joined: 05 Jan 2006
Posts: 7

PostPosted: Tue Jan 24, 2006 9:28 am    Post subject: checkboxes Reply with quote

Thanks a lot Exclamation Exclamation Exclamation

It's the answer to my question in french :
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=7098 Mr. Green
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP