javascript - Html form: easiest way to define value of control based on other controls on client side -


i want send age instead of year born form server when submit button clicked. easiest way achieve it?

<form action="process.php">     <input type="text" name="yearborn">     <input type="hidden" name="age">     <input type="submit" > </form> 

here options, in personal preference order.

server

handle on server. understand don't solution, if use has javascript disabled? cases makes sense, when don't control server (e.g. submitting other site's page).

it's security risk. send fake post saying year of birth 2042 , i'm 39,239 years old, reason cause app crash, if try store in 16 bit signed integer.

mvc, mvvm, etc.

use solution lets define links between data , view. here's knockoutjs example, while people prefer backbone or angularjs.

<input type="text" name="yearborn" data-bind="value: yearborn"> <input type="hidden" name="age" data-bind="value: 2013 - parseint(yearborn())"> 

handle in change handler (more reliable blur).

$('input[name=yearborn]').change(function(){     $('input[name=age]').val(2013 - parseint($(this).val())); }); 

it can triggered.

$('input[name=yearborn]').val('1993').change(); // sets age 20 

ask them age

might worth considering, it's app.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -