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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
samSOUND
Forum Newbie
Posts: 2
Joined: Mon Jan 17, 2011 12:43 pm

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

Post 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
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

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

Post by Peter Kelly »

This can be easily done with Javascript. I presume they would be in the same form?
samSOUND
Forum Newbie
Posts: 2
Joined: Mon Jan 17, 2011 12:43 pm

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

Post by samSOUND »

yeah they are on the same form

what do i do?
Post Reply