Sangeetha Pinto
Sangeetha Pinto

Reputation: 1022

Detect click on HTML option tag through javascript in Android WebView

I have a form in a webview. I'm able to detect button clicks and perform required tasks.But in the form, there is a option tag. Based on the selected item type, I should perform next task. But I'm unable to detect the option click event. I tried both with onClick and onChange. Both doesn't work. Any idea how to detect its click event?

I tried the below code in my html code:

  <div class="label"><b>Type :</b></div>
            <div class="field">
                <select name="type" >
                    <option value="video" selected="selected" onchange="videos.performClick()">video</option>
                    <option value="image" onchange="images.performClick()">image</option>
                </select>
            </div>
        </div>

Upvotes: 0

Views: 1101

Answers (1)

Vigneswaran Marimuthu
Vigneswaran Marimuthu

Reputation: 2532

You need to listen for onchange event on select field.

<div class="label"><b>Type :</b></div>
        <div class="field">
            <select name="type" onchange="onSelectFieldChange(this)">
                <option value="video" selected="selected">video</option>
                <option value="image">image</option>
            </select>
        </div>
    </div>

Now you write onSelectFieldChange function which handles redirection based on the selected option.

    function onSelectFieldChange(element) {

        switch(element.value) {
        case 'video':
            videos.performClick()
            break;
        case 'image':
            images.performClick()
            break;
        default:
            break;
        }

    }

Upvotes: 1

Related Questions