0

I create for my project a year/month enter widget in Yii.

(It is planned to be implemented as two <select> tags, one for a year and one for a month. I plan to reboot the page on every change (be it year change or month change). But that are unimportant details.)

I may pass 'onchange' attribute with some JavaScript to the widget in my PHP code.

Now to the question: This JavaScript should have access to the values year and month. How to pass these values to JavaScript code in an implementation agnostic way? (I mean that for example I may change the year input field to be a text input instead of a <select> or whatever changes we may wish). This change should not change the way year and month are passed to JavaScript.

Any ideas?

2 Answers 2

1

You can use keyword 'this' in JavaScript for that purpose. So try that (need JQuery):

<select onchange="func(this)">
    <!--options here-->
</select>

<input onchange="func(this)">

<script>
function func(obj) {
    var value = $(obj).val();
    // logic..
}
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of passing some JavaScript code as onchange attribute, I may pass a two-argument (year, month) JavaScript function as some other attribute.

Is it the best solution?

Comments

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.