views:

57

answers:

1

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.

+3  A: 

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
Gipsy King
This way I get the value of 'repeat' correctly and works fine on the 'if' condition but the <div name="endR"> is not visible still.
framara
you can only get form elements by form.elementName; a div is a regular element so the name attribute is not valid. You should use the id attribute, and access it by document.getElementById('divId').
Gipsy King