Page 1 of 1

how can I autofill a field depending on a previous field?

Posted: Mon Jan 17, 2011 12:50 pm
by samSOUND
hi, I have created two fields that only accept numerical values. What I would like is if the second field is left blank to be auto filled with the first field but with an extra amount added on.

Code: Select all

$form['base']['number']['one'] = array(
    '#type' => 'textfield',
    '#title' => t('one'),
    '#required' => TRUE,
    '#weight' => 1,
    '#size' => 20,
    '#maxlength' => 35,
 );
  $form['base']['number']['two'] = array(
    '#type' => 'textfield',
    '#title' => t('two'),
    '#required' => FALSE,
    '#weight' => 2,
    '#size' => 20,
    '#maxlength' => 35,
 );
this is my current code, what I want is some code that says, auto fill field two with the amount entered into field one but with 10.00 added on.

how can I do this?

Thanks for any help

Re: how can I autofill a field depending on a previous field

Posted: Tue Jan 18, 2011 7:00 am
by Peter Kelly
This can be easily done with Javascript. I presume they would be in the same form?

Re: how can I autofill a field depending on a previous field

Posted: Tue Jan 18, 2011 1:05 pm
by samSOUND
yeah they are on the same form

what do i do?