jQuery select form items based on name startswith...

41 views
Skip to first unread message

Jordan Ladora

unread,
Jul 1, 2014, 12:14:41 PM7/1/14
to web...@googlegroups.com
Hi,

I'm trying to make a button that will check some boxes in a form based on the checkboxes' name attributes.

But I can't get this to work-
<div id='div2'>
  <button onclick="event.preventDefault();jQuery('input[name^='somecheckbox']').each(function(k){jQuery(this).prop('checked', false);});">Deselect All</button>
</div>

I'm basing it off http://api.jquery.com/attribute-starts-with-selector/

I've tried a few different things but cannot get it to do anything good..

Thanks for any pointers,
-jl

Niphlod

unread,
Jul 1, 2014, 3:02:55 PM7/1/14
to web...@googlegroups.com
1st rule: never, never, never use inline javascript.
2nd rule: start with console.log() and an open debugger (firebug, chrome developer tools, etc)
3rd rule: use the quotes! you are terribly wrong with those
3rd rule: simplify the code, then expand.

$('#div2 button').on('click', function() {
       console.log($("input[name^='something'"))
})

Jordan Ladora

unread,
Jul 1, 2014, 3:53:42 PM7/1/14
to web...@googlegroups.com
Thanks, Niphlod, that is very helpful.. I think I'm on the right track now!


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/oZ_u_XPbEys/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages