0

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>

1 Answer 1

1

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;
        }

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

4 Comments

@ Vigneswaran Marimuthu, sometimes even though I have selected the option type, javascript doesn't get called. Why is this is happening..is there anything specific that ahs to be done?
@AmandaFernandez If you select the same option which is already selected, then onchange won't be called.
I know..I'm getting this issue at this scenario. 1. When I select the type, the corresponding types gets selected and shows me the filechooser. 2. There is a upload button in my webview. after clicking on the that the page loads again. After that onchange never gets called.
@AmandaFernandez Can you tell me which scenario ? I couldn't get what you meant by "at this scenario".

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.