0

I am creating with a mouse event two float values in a javascipt jquery function and pass these values via form to a spring mvc controller as parameters. It works fine when the values get actually created but when I do not create them, the form passes a string "undefined" and the whole thing crashes.

my javascript values:

$('#width').val(event.pageX);
$('#height').val(event.pageY);

my form:

<form:form modelAttribute="Float2" method="POST" action="getFloats">
<input type="hidden" id="width" name="width" value=width>
<input type="hidden" id="height" name="height" value=height>
<button type="submit">Save the floats</button>

Is there a possibility to change the "undefined" to zero so that the form always passes floats?

krenkz
  • 484
  • 6
  • 15

1 Answers1

1

Well, one option is to create html input tags already with the default values:

<input type="hidden" id="width" name="width" value="0">
<input type="hidden" id="height" name="height" value="0">

Then alter this values with JS if you need, otherwise default "0" values will be submitted

tarkh
  • 2,424
  • 1
  • 9
  • 12