in Education by
I am working on an application form with multiple Date of Birth fields. I have created a simple date input with select elements. When the select elements change the values are copied into an additional hidden text field to keep the results. I have written a function that I want to apply to all the instances of this date input, however, it repeats the same values in the additional date inputs after the first has been filled in. I think it has something to do with how the variables are set for the function. How can I get the function to apply to each instance I apply it to without repeating the results? Js Fiddle example here : http://jsfiddle.net/allyreid/JyE8b/5/ Help appreciated. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here is the fix: $.fn.dateofbirth = function() { return this.each(function() { $(this).children('select').change(function(){ var cont = $(this).parent(); var day = $("select[name='Day']", cont).val(); var month = $("select[name='Month']", cont).val(); var year = $("select[name='Year']", cont).val(); var fullDate = day + " / " + month + " / " + year; $(this).parent().find('.result').val(fullDate); }); }); }; $('td.dob').dateofbirth(); You problem here is that on the "onChange" event, you're selecting the values using: $("select[name='Day']").val(); and that is only selecting the FIRST day dropdown, that's why you always get the same value. The fix consists on first getting the parent element of the element that originated the change event and then working with the dropdowns that are INSIDE that parent. If you have questions about the core, let me know. One more thing This is what did the trick: When selecting elements with jQuery, you can specify the container inside where to look for. That's what I did there, you have $(SELECTOR STRING, container_element)

Related questions

0 votes
    I am working on an application form with multiple Date of Birth fields. I have created a simple date ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    _____ clause is an additional filter that is applied to the result. (a) Select (b) Group-by (c) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
0 votes
    I have an autocomplete that's almost working as I want it to work. The problem that I have is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have an autocomplete that's almost working as I want it to work. The problem that I have is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I used the example from here http://jqueryui.com/demos/dialog/#animated to create a dialog box. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    A fair coin is tossed repeatedly. The probability of getting a result in fifth toss different from those obtained in the ... 32D.1//16` Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    A fair coin is tossed repeatedly. The probability of getting a result in fifth toss different from those obtained in the ... D. 1 16 Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Which effects are applied to an individual element on a single slide? Select the correct answer from above options...
asked Dec 12, 2021 in Education by JackTerrance
0 votes
    If you have used inline, internal, and external all the 3 stylings in HTML for a single element then which style will be ... . Inline 2. Internal 3. External 4. None of the above...
asked Jul 12, 2021 in Technology by JackTerrance
0 votes
    I want to disable the sort property in dataTable API. I use bsort:false to disable sorting from all ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Is there a built-in that removes duplicates from a list in Python, whilst preserving order? I know that I can ... idiom if possible. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
...