jQuery Question

How add value to input

I have a short question. I need add value in all input on page, but it value not save. This is my code:

$('.formInput').val('1')


How I can input value and save result?

Answer

Like this? I don't clearly about "How I can input value and save result?". I hope it can help you :)

$('.formInput').val('1')
var value = $('.formInput').val();
$('.getValue').click(function(){
  alert(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input class="formInput" type="text" />
<input type="submit" class="getValue" value="Get Value" />
</form>