[jQuery] Re: Checkboxes enabled/disable button
Morningz, Thank you for this! I made a couple of small changes, like so: if ($(inp...@name='my_checkbox']:checked).length == 0) { and it worked a real treat!! Thank you for your advice, I appreciate it! Robert -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of MorningZ Sent: 18 February 2009 13:11 To: jQuery (English) Subject: [jQuery] Re: Checkboxes enabled/disable button if ($(checkbox[name='my_checkbox']:checked).length == 0) { //None are checked } else { //At least one is checked } Sir Rawlins wrote: Hello Guys, Fairly noobish here so hoping to learn a little something from this challenge. I have a form which contains a bunch of different checkboxes (all the same name) and a bunch of different button elements. I want to by default have these buttons disabled unless at least one checkbox is checked, if no checkboxes are checked then they need to be disabled. input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / button type=buttonClick me to do something/button button type=buttonClick me to do something else/button button type=buttonClick me to do something cool/button button type=buttonClick me to do nothing/button If this were just a single checkbox then I could figure this out without too much hassle but I'm unsure as to how I should be checking is any of the boxes are checked, presumably we can do some sort of array count for instances of it or something? who knows? I'd appreciate your thoughts on this guys. Robert
[jQuery] Re: Checkboxes enabled/disable button
Thanks for the heads up on that, I've obviously picked that up as a bad habbit from some examples built on older versions, I'll be sure to get rid of it! :-) Thanks Robert -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of MorningZ Sent: 18 February 2009 15:49 To: jQuery (English) Subject: [jQuery] Re: Checkboxes enabled/disable button Don't use @ well, don't use it if you plan on ever using jQuery over version 1.3... because it's not supported even if you are using an older version, loose the @, it's not needed On Feb 18, 10:13 am, Robert Rawlins robert.rawl...@thinkbluemedia.co.uk wrote: Morningz, Thank you for this! I made a couple of small changes, like so: if ($(inp...@name='my_checkbox']:checked).length == 0) { and it worked a real treat!! Thank you for your advice, I appreciate it! Robert -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of MorningZ Sent: 18 February 2009 13:11 To: jQuery (English) Subject: [jQuery] Re: Checkboxes enabled/disable button if ($(checkbox[name='my_checkbox']:checked).length == 0) { //None are checked } else { //At least one is checked } Sir Rawlins wrote: Hello Guys, Fairly noobish here so hoping to learn a little something from this challenge. I have a form which contains a bunch of different checkboxes (all the same name) and a bunch of different button elements. I want to by default have these buttons disabled unless at least one checkbox is checked, if no checkboxes are checked then they need to be disabled. input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / input type=checkbox name=my_checkbox / button type=buttonClick me to do something/button button type=buttonClick me to do something else/button button type=buttonClick me to do something cool/button button type=buttonClick me to do nothing/button If this were just a single checkbox then I could figure this out without too much hassle but I'm unsure as to how I should be checking is any of the boxes are checked, presumably we can do some sort of array count for instances of it or something? who knows? I'd appreciate your thoughts on this guys. Robert
[jQuery] Re: Change link dependant on select box.
Morning Morningz, Why wouldn't you just have select name=customer id=customer option value=50ccdae0-79bf-11dd-ad8b-0800200c9a66Joe Bloggs/option option value=9c335820-d878-4db3-b90a-728046cb8849Dave Something/option /select a id=CompanyLink/a script type=text/javascript $(document).ready(function() { $(#customer).change(SetLink); SetLink(); }); function SetLink() { var obj = document.getElementById(#customer); obj = obj.options[obj.selectedIndex]; $(#CompanyLink) .attr(href, '/view_customer_company.cfm?company_id=' + obj.value) .html('View ' + obj.text + ' Company'); } /script deeming the key/value lookup unnecessary? The reason I can't do this is because the 9c335820-d878-4db3-b90a-728046cb8849 isn't the ID of the customer which is ultimately what I need when I submit the form, so this has to stay as the numeric ID value. The link which changes is just a usability thing to allow my users to quickly check the background of the customer before they submit the form, but to check the background I need their company_id, which is why we need the key:value pair. Is the key:value pair complicated to implement into your above example? I understand the code you've provided but wouldn't really know where to start enhancing it. Thanks for your advice mate, I appreciate it. Robert
[jQuery] Re: Change link dependant on select box.
Morningz, As another little note, I was testing your example code this morning but I get an 'Object Required' error thrown by it, any ideas what might be causing this? I definitely have the HTML elements with the correct ID's present on the page, any other thoughts? Don't worry about the key:value pair side of things as I can probably solve that little challenge with some Server Side scripting which will be more robust. If we can get the error resolved the example you've given should give me exactly what I need :-) Thanks, Robert
[jQuery] Re: Change link dependant on select box.
Morningz, That's exactly what it was, I took out the pound sign and it work perfectly! Thanks mate, I appreciate the help. Robert -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of MorningZ Sent: 04 September 2008 13:18 To: jQuery (English) Subject: [jQuery] Re: Change link dependant on select box. that example above was totally off the top of my head to try to point you the way i do quickly see one issue with it though var obj = document.getElementById(#customer); should not have the # sign var obj = document.getElementById(customer);
[jQuery] Change link dependant on select box.
Hello Guys, I'm looking for some help on getting started with a script that'll change the href attribute of a link dependant on the option selected in a select box. To add a little 'spice' the challenge the value of the href must be determined from a set of key value pairs. Let me try and offer an example. I have a select box like this: select name=customer id=customer option value=1Joe Bloggs/option option value=2Dave Something/option /select And the link which I want to change dependant on the selection looks something like this: a href=/view_customer_company.cfm?company_id=6View Customers Company/a I've highlighted the bits in red which I wish to make dynamic dependant on the option chosen in the select box. Where I've put 'customers' I want to dynamically change to the option text, such as 'Joe Bloggs' or 'Dave Something' and the company_id value I need to pull from a key/value set using the option value as the key, such as 1 or 2. The key/value pairs look something like this: Key:value 1: 50ccdae0-79bf-11dd-ad8b-0800200c9a66 2: 9c335820-d878-4db3-b90a-728046cb8849 So, as a quick summation of the expected results, If I select 'Joe Bloggs' in my select list, I want the link to be changed to: a href=/view_customer_company.cfm?company_id=50ccdae0-79bf-11dd-ad8b-0800200c 9a66View Joe Bloggs Company/a And likewise, if I chose 'Dave Something' in the select list the link would look like this: a href=/view_customer_company.cfm?company_id=9c335820-d878-4db3-b90a-728046cb 8849View Dave Something Company/a I'm really a novice with both JavaScript and jQuery for the moment, I'm learning well but this is a little bit beyond me, especially when you're looking at working with the key/value paris. I appreciate any help you can offer and thanks in advance for your time. Robert
[jQuery] enable/disable to text inputs with checkbox
Good afternoon guys, I'm pretty much a jQuery novice and I'm looking for your advice on how to achieve this task. I have two input fields which I want to be disabled by default, with a checkbox which is checked. Then, if a user unchecks the checkbox it will enable the two fields for them to enter data in. In addition to this, if they enter information into the two fields and then recheck the box, I would like it to clear any values they entered and disable them again. Can anyone offer any pointers or code for this? Many thanks guys, Robert
[jQuery] Re: enable/disable to text inputs with checkbox
Hi Karl, This is very generic, so you'll have to be more specific with your selectors, but it should give you an idea of how to do this: $(document).ready(function() { $('input:checkbox').click(function() { if ($(this).is(':checked')) { $('input:text').val('').attr('disabled', true); } else { $('input:text').attr('disabled', false); } }); }); Thanks for this, I updated the selectors for #my_input_id and it works an absolute treat! Thank you. Robert
[jQuery] Re: Ensure Textarea has been read.
Hi Ariel, Thanks for getting back to me. That looks like a neat and tidy piece of code however it isn't working. I don't get any JavaScript errors throw which is a good thing, but is doesn't re-enable the checkbox when I scroll to the bottom. label for=terms accesskey=TemT/emerms amp; Conditions:/label textarea name=terms id=termsjkhkjhkjhkjhkhkhkjhsf kjsdfkjhsd kheuh/textarea br / label for=agree accesskey=a input type=checkbox name=agree id=agree disabled=true / I emA/emgree to the Terms amp; Conditions /label That's the HTML mark-up I'm using for the text area and checkbox, I've changed the id's in the JS snippet to match up with the id's of the fields: script type=text/javascript $('#terms').scroll(function(){ if( $(this).scrollTop() == $(this).height() ) $('#agree').attr('disabled', false); }); /script Any suggestions on this? Cheers mate, Rob -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ariel Flesler Sent: 13 June 2008 16:40 To: jQuery (English) Subject: [jQuery] Re: Ensure Textarea has been read. I haven't tested this, but it should be something like this: $('#terms').scroll(function(){ if( $(this).scrollTop() == $(this).height() ) $('#submit').attr('disabled', false); }); Cheers -- Ariel Flesler http://flesler.blogspot.com On 13 jun, 10:44, Sir Rawlins [EMAIL PROTECTED] wrote: Afternoon All, I have a form which includes a textarea, inside the text area I'm displaying the terms and conditions of a service which a user must agree too before continuing thier registration process. I want to have the checkbox which they must select to accept the terms and conditions to be disabled untill they have scrolled down to the bottom of the textarea. I'm a total and utter noob when it comes to jQuery and have a relativly limited knowledge of JS in general so would really appreciate your advice on how to handle this challenge. Thanks guys, Rob