1

I have a really simple javascript function to return the index of a selected field, it looks like this:

function validateForm() { 
    alert(document.getElementByID('textfieldAmount').selectedIndex);
    return false;
}

This is called from an input button onClick like this:

onclick="return validateForm();" 

but the Javascript is never called and the page is submitted anyway.

If i change the alert to alert("wibble"); the alert works fine and the page is not submitted.

The element i am querying looks like this:

<select name="textfieldAmount" id="textfieldAmount" class="form">

Any ideas why its not working before i kill myself?

1 Answer 1

5

javascript is case-sensitive:

alert(document.getElementById('textfieldAmount').selectedIndex);
Sign up to request clarification or add additional context in comments.

1 Comment

specifically: ID should be `Id'

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.