0

I am a very beginner in javascript and I would like to change a single input value when the user selects an option with a form, thhen submit it to the same page.

here is the Html code:

<form id="form" action="thispage.jsp" method="post">
<input id="action_type" type="hidden" name="action_type" value="firstAction" />
<table class="choose">
    <tr>
        <td>Choose your test</td>
        <td><select id="select_test" name="test_name">
            <option value="test0"></option>
            <option value="test1"></option>
        </select></td>
    </tr>
</table>

And the javascript function:

form = document.getElementById("form");
action = document.getElementById("action_type");
select = document.getElementById("select_test");
select.onchange = function() {
    action.setAttribute("value", "otherAction");
    form.submit();
}

And this returns an Exception, what is wrong with this code ?

2
  • What exception is being returned? Commented Aug 31, 2012 at 15:32
  • As I said to Fabian, it was a NullPointerException from org.apache.jsp.someGeneratedClass._jspService Commented Aug 31, 2012 at 16:59

3 Answers 3

1

It doesn't seem to be a problem with JavaScript, but with your JSP code. Try debugging the code and check where it's failing.

Sign up to request clarification or add additional context in comments.

Comments

1

I think the form is not defined. try to add a var before the form.

1 Comment

I'm sorry, the actual source of my errors was nos in this portion of code. It's sad that I only get a NullPointerException from org.apache.jsp.someGeneratedClass._jspService as It's difficult to debug. Thanks anyway.
0

I think nullPointer shows because there is no selected option. Since the code does not have any innerHTML on it, you cant choose anything.

Comments

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.