gman171966
gman171966

Reputation: 1

javascript myform.action doesn't

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!

Upvotes: 0

Views: 38

Answers (1)

Florian Margaine
Florian Margaine

Reputation: 60787

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 :)

Upvotes: 2

Related Questions