artur
artur

Reputation: 684

Get value from text field and show in select field

Hi I have cna someone help me with this i want to get vlaue from text field and show in select with javascript or jquery.

        <ul class="title_customer">
            <li>
        <label for="offaddress" class="title_register"><!--<em>*</em>--><?php echo $this->__('Title') ?></label>
        <div class="input-box">
           <div type="text" name="offaddress1" id="offaddress1" value="<?php echo $this->htmlEscape($this->getCustomer()->getOffaddress()) ?>" title="<?php echo $this->__('Office Address') ?>" class="input-text " >
            <input type="text" name="offaddress1" id="offaddress1" value="<?php echo $this->htmlEscape($this->getCustomer()->getOffaddress()) ?>" title="<?php echo $this->__('Office Address') ?>" class="input-text" />
           </div>
        </div>

    </li>
        <li>
        <label for="offaddress" class="title_register"><!--<em>*</em>--><?php echo $this->__('Choose Title') ?></label>
        <div class="input-box">
           <select type="text" name="offaddress" id="offaddress" value="<?php echo $this->htmlEscape($this->getCustomer()->getOffaddress()) ?>" title="<?php echo $this->__('Office Address') ?>" class="input-text " >
               <option value="DEP">DEP</option>
               <option value="DR">DR</option>
               <option value="MISS">MISS</option>
               <option value="MR">MR</option>
               <option value="MRS">MRS</option>
               <option value="MS">MS</option>
               <option value="SIR">SIR</option>
               <option value="LS">LS</option>
           </select>
        </div>
    </li>
    </ul>

Upvotes: 0

Views: 146

Answers (1)

user818991
user818991

Reputation:

You can run a loop on your options inside of a blur function if a user inputs themselves e.g

var b;
$('#offaddress1').on('blur',function(){
  var a = $(this).val();        
  $('#offaddress option').each(function(){
    b = $(this).val();
    $(this).val(b + ' ' + a).html(b + ' ' + a);
  });
});

or you can read the current value if it is filled on page load by doing something like

var b;
var a = $('#offaddress1').val();        
$('#offaddress option').each(function(){
  b = $(this).val();
  $(this).val(b + ' ' + a).html(b + ' ' + a);
});

you could/should tidy the variable names and also tweak it so it runs on page load and on blur.

The problem is you are using the same ID for your input and wrapping div so unless you change that it wont work.

I've not tested these at any great length as you didn't add any attempts

Upvotes: 1

Related Questions