0

I'm trying to use javascript in JSP with a form. The form has a dropdownlist with an onchange event to call a function to sumbit the selected value to a servlet. I'm getting an error "Object doesn't support this action". What is the syntax error in my code?

Here is my code:

<form id="input" method="post" action="ResultServlet">
<input id=year type=text value="george">
<input id=year type=text value="mary">
<input id=year type=text value="fred">

<select id=casesId onchange = "sendCases();">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3 </option>
</form>

<script typ=text/javascript>

function sendCases(){
var id = document.forms[0].caseId.options[document.forms[0].caseId.selectedIndex.value;

  if (id !='' || id == null{
   document.forms[0].action('CaseServlet').submit();
  }
}
</script>

Any help you could give would be great. Thanks!

1 Answer 1

2

Change:

if (id !='' || id == null{
    document.forms[0].action('CaseServlet').submit();
}

For:

if (id!='' || id == null) {
    document.forms[0].action = 'CaseServlet';
    document.forms[0].submit();
}
  1. You have a syntax error where you forget to close the if. It might be a typo though.
  2. action is not a method, it's a property. You don't execute it, you assign a value to it.
  3. The submit() method only works on the form object, not something else :)
Sign up to request clarification or add additional context in comments.

1 Comment

oops, ) left out of if statement... :) Thanks, tried what you suggested and it works.

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.