framara
framara

Reputation: 2963

Display input element when select option

I have a select element in the form with different options. On property of the 'select' is onchange="testRecurrence(this.form)" and the js function it's just:

function testRecurrence(form) {
    if(form.repeat.value != "N") {
        form.endR.style.display = 'inline';
    }

    return true;
}

Being 'repeat' the select and 'endR' the item I want to display in case the option value is not "N". The issue here is that this is not working... been trying to find a solution but not able. Any help?

update Not working, the element stay always hidden. The element endR by default has display:none.

update2 js function changed to:

function testRecurrence(form) {
    if(form.repeat.options[form.repeat.selectedIndex].value != 'N')
        document.getElementById('endR').style.display = 'inline';        
}

html:

<select name="repeat" onchange="testRecurrence(this.form)">
...
<div id="endR" style="display: none">
...
</div>

It works now. Thank you.

Upvotes: 2

Views: 1032

Answers (1)

Gipsy King
Gipsy King

Reputation: 1577

I think getting the value of a select element doesn't work on all browsers, but this should do:

form.repeat.options[form.repeat.selectedIndex].value

Upvotes: 3

Related Questions