2

I am wondering if it's possible to restore dropdown values once they have been cleared by jquery?

In this example you can see that when you check one of the checkboxes, it disables and clears the corresponding dropdowns. Once the checkbox is unchecked, the values are gone.

Is i possible to only have the values cleared when the checkbox is checked?

http://jsfiddle.net/ZXSKH/32/

3 Answers 3

1

I won't question whether it's necessary or not. This answers your question...

http://jsfiddle.net/ZXSKH/38/

Sign up to request clarification or add additional context in comments.

Comments

0

Removing the options is unnecessary since you're already disabling the selects. Simply reduce the width of the disabled selected to simulate the removal of the options:

//Remove this line
$('div[day_id="' + $(this).val() + '"] select').find('option').remove()

//Replace with this:
selects.css("width", "22px");

//Don't forget to restore the width when enabling the selects:
selects.css("width", "75px");

Here's a working fiddle.

2 Comments

I remove the options because when posted to the database it wont post the default hours in the dropdown options. That way when i read the values from the database it won't look like they filled in the values and I will get correct hours. Unless I could solve that in another way?
You can prepend a value to each and then remove that prepended value
0

why u need to remove select options ?

http://jsfiddle.net/ZXSKH/36/

u can try this. Change this line

$('div[day_id="'+$(this).val()+'"] select').find('option').remove() 

to

$('div[day_id="'+$(this).val()+'"] select').attr('disabled','') 

2 Comments

I remove them because when posted to the database it would post the wrong values? Or am I wrong? I mean when someone selects the checbox and submits the form the fields should be empty or am getting this wrong?
while u are reading the data for send server, u can filter it with default values or disabled attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.