1

Code is as follows:

function change_course(ref) 
{ 
      var arr = ref.split(/\^/);
  document.getElementById('course').value  = arr[0];
  document.getElementById('course_date').value  = arr[1]; 
}

This will throw an "Uncaught TypeError: object is not a function".

<select name="change_course" class="form-control" onChange="change_course(this.value);">';

Where is wrong

6
  • 1
    From which line is the exception been thrown? Commented Aug 31, 2014 at 18:26
  • Maybe there are no elements with the ids course and course_date? Commented Aug 31, 2014 at 18:27
  • @Bergi - No i creat tow element like :- <input type="hidden" name="course" id="course"> <input type="hidden" name="course_date" id="course_date"> Commented Aug 31, 2014 at 18:59
  • Why there is a single quote after 'select' tag? Is it inside a variable? Can you show example of options for the select (<option><option/>) Commented Aug 31, 2014 at 19:15
  • 2
    One of the many pitfalls of using inline event handlers. See onclick=“” vs event handler for an explanation. Commented Aug 31, 2014 at 19:25

1 Answer 1

2

Inline onchange is executed within the same scope as the form element (or inner), and change_course refers to the select element, not to the global function.

To fix this, just give a new value to select's name attribute, or rename the function.

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

2 Comments

While the <select> element is in the scope of the event handler, this particular issue likely exists because the containing <form> element is in the scope. A form element has a property for each input, select, etc it contains (which also feels like an a very unexpected behavior).
@FelixKling Looks like you're right, the wrapping form element is the one, where change_course is found. If the form is stripped, the error doesn't occur.

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.