[jQuery] Re: Checkbox behaviour
In general, form selections will persist when the page is refreshed. If you add a random query string like ?foo=bar, you should see your selections reset. In regards to james' comments above, I think it would be far cleaner to reset the form before the page unloads. This is a simple task: $(window).unload(function() { $(form).each(function() { this.reset() // call reset on the raw node }); }); On Aug 7, 7:38 pm, James james.gp@gmail.com wrote: You can have as many document ready checks as you want. I'd like to keep things organized by only having one though. As for the checkbox being selected by default when the page loads, you can do either of two things: 1) run the function on page load that checks for the checkbox and do any changes 2) or run a code to that unchecks the checkbox on page load so that it's always unchecked on page load. On Aug 7, 5:18 am, Samuurai djbe...@gmail.com wrote: Sorry Johnathan, I sent a seperate reply, but it never came through. Thanks for your input.. My question about it was... is it bad practice to have more than one $(document.ready(function(){}) scripts, or can I have multiple? Cheers, Beren On Aug 7, 1:43 pm, Jonathan Vanherpe (T T NV) jonat...@tnt.be wrote: You'll have to run the whole function block within $(#show_resolve).click() on load (ie. put it somewhere in $(document).ready(function(){}). Make it a seperate function so you can avoid copy/pasting the whole thing Jonathan Samuurai wrote: Hi, This is my first little foray into JQuery, so far i'm impressed, having had very little JS experience, I was able to create the result I wanted very qucikly and easily! However, I'm having one little niggle... Here's my code: [code] $(document).ready(function(){ $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).css(visibility,visible); $(#left_submit).css(visibility,hidden); } else { $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); } }); }); [/code] This works fine.. ticking the checkbox shows and hides the div. However, if I check the checkbox and refresh the page, the checkbox remains ticked, but the div is hidden. Any ideas how I can make it work reliably? -- Jonathan Vanherpe - Tallieu Tallieu NV - jonat...@tnt.be
[jQuery] Re: Checkbox behaviour
You'll have to run the whole function block within $(#show_resolve).click() on load (ie. put it somewhere in $(document).ready(function(){}). Make it a seperate function so you can avoid copy/pasting the whole thing Jonathan Samuurai wrote: Hi, This is my first little foray into JQuery, so far i'm impressed, having had very little JS experience, I was able to create the result I wanted very qucikly and easily! However, I'm having one little niggle... Here's my code: [code] $(document).ready(function(){ $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).css(visibility,visible); $(#left_submit).css(visibility,hidden); } else { $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); } }); }); [/code] This works fine.. ticking the checkbox shows and hides the div. However, if I check the checkbox and refresh the page, the checkbox remains ticked, but the div is hidden. Any ideas how I can make it work reliably? -- Jonathan Vanherpe - Tallieu Tallieu NV - jonat...@tnt.be
[jQuery] Re: Checkbox behaviour
I've changed it a little bit, so it doesn't show/hide the div, it's meant to disable the input elements: Can anyone see why ticking it works, but unticking it leaves the input tags disabled still? script type=text/javascript $(document).ready(function(){ $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).children(:input).attr (disabled, disabled); } if ($(#show_resolve).is(:checked)) { $(.submit.problem_form_right).children(:input).removeAttr (disabled); } }); }); /script Thank you! On Aug 7, 1:43 pm, Jonathan Vanherpe (T T NV) jonat...@tnt.be wrote: You'll have to run the whole function block within $(#show_resolve).click() on load (ie. put it somewhere in $(document).ready(function(){}). Make it a seperate function so you can avoid copy/pasting the whole thing Jonathan Samuurai wrote: Hi, This is my first little foray into JQuery, so far i'm impressed, having had very little JS experience, I was able to create the result I wanted very qucikly and easily! However, I'm having one little niggle... Here's my code: [code] $(document).ready(function(){ $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).css(visibility,visible); $(#left_submit).css(visibility,hidden); } else { $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); } }); }); [/code] This works fine.. ticking the checkbox shows and hides the div. However, if I check the checkbox and refresh the page, the checkbox remains ticked, but the div is hidden. Any ideas how I can make it work reliably? -- Jonathan Vanherpe - Tallieu Tallieu NV - jonat...@tnt.be
[jQuery] Re: Checkbox behaviour
Sorry Johnathan, I sent a seperate reply, but it never came through. Thanks for your input.. My question about it was... is it bad practice to have more than one $(document.ready(function(){}) scripts, or can I have multiple? Cheers, Beren On Aug 7, 1:43 pm, Jonathan Vanherpe (T T NV) jonat...@tnt.be wrote: You'll have to run the whole function block within $(#show_resolve).click() on load (ie. put it somewhere in $(document).ready(function(){}). Make it a seperate function so you can avoid copy/pasting the whole thing Jonathan Samuurai wrote: Hi, This is my first little foray into JQuery, so far i'm impressed, having had very little JS experience, I was able to create the result I wanted very qucikly and easily! However, I'm having one little niggle... Here's my code: [code] $(document).ready(function(){ $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).css(visibility,visible); $(#left_submit).css(visibility,hidden); } else { $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); } }); }); [/code] This works fine.. ticking the checkbox shows and hides the div. However, if I check the checkbox and refresh the page, the checkbox remains ticked, but the div is hidden. Any ideas how I can make it work reliably? -- Jonathan Vanherpe - Tallieu Tallieu NV - jonat...@tnt.be
[jQuery] Re: Checkbox behaviour
Hi There Try this [code] $(document).ready(function(){ if ($(#show_resolve).is (:checked)) { $ (.submit_problem_form_right).css(visibility,visible); $(#left_submit).css (visibility,hidden); } $ (.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css (visibility,visible); $(#show_resolve).click (function () { if ($(#show_resolve).is (:checked)) { $ (.submit_problem_form_right).css(visibility,visible); $(#left_submit).css (visibility,hidden); } else { $ (.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css (visibility,visible); } }); }); [/code]
[jQuery] Re: Checkbox behaviour
You can have as many document ready checks as you want. I'd like to keep things organized by only having one though. As for the checkbox being selected by default when the page loads, you can do either of two things: 1) run the function on page load that checks for the checkbox and do any changes 2) or run a code to that unchecks the checkbox on page load so that it's always unchecked on page load. On Aug 7, 5:18 am, Samuurai djbe...@gmail.com wrote: Sorry Johnathan, I sent a seperate reply, but it never came through. Thanks for your input.. My question about it was... is it bad practice to have more than one $(document.ready(function(){}) scripts, or can I have multiple? Cheers, Beren On Aug 7, 1:43 pm, Jonathan Vanherpe (T T NV) jonat...@tnt.be wrote: You'll have to run the whole function block within $(#show_resolve).click() on load (ie. put it somewhere in $(document).ready(function(){}). Make it a seperate function so you can avoid copy/pasting the whole thing Jonathan Samuurai wrote: Hi, This is my first little foray into JQuery, so far i'm impressed, having had very little JS experience, I was able to create the result I wanted very qucikly and easily! However, I'm having one little niggle... Here's my code: [code] $(document).ready(function(){ $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); $(#show_resolve).click(function () { if ($(#show_resolve).is(:checked)) { $(.submit_problem_form_right).css(visibility,visible); $(#left_submit).css(visibility,hidden); } else { $(.submit_problem_form_right).css(visibility,hidden); $(#left_submit).css(visibility,visible); } }); }); [/code] This works fine.. ticking the checkbox shows and hides the div. However, if I check the checkbox and refresh the page, the checkbox remains ticked, but the div is hidden. Any ideas how I can make it work reliably? -- Jonathan Vanherpe - Tallieu Tallieu NV - jonat...@tnt.be