0

In the given html code name_with_initials such as mr,mrs,ms,master.While retrieving name from database it is like "MR:Raju" Based on this value i need to select value in of prefix name(MR) and name(Raju) should be in input box.How to do this?

<div class="input-group">
                  <span class="input-group-addon">
                    <select name="name_with_initials" id="name_with_initials">
                      <option value="MR">MR</option>
                      <option value="MRS">MRS</option>
                      <option value="MS">MS</option>
                      <option value="MASTER">MASTER</option>
                    </select>
                  </span>
                  <input type="text" name="name_with_initials" id="customername" onKeyPress="return ValidateAlpha(event);" class="form-control detailinfo" placeholder="Full Name">
                </div><!-- /input-group -->
3
  • have u tried something so far? Commented Oct 24, 2018 at 11:48
  • 1
    So effectively, you are asking how you can split a string value at a particular character, in this case the colon? That is something you should be able to easily research on your own, for nearly any programming language. Please make an effort. Commented Oct 24, 2018 at 11:52
  • Possible duplicate of Regex to split HTML tags Commented Oct 24, 2018 at 12:27

1 Answer 1

2

You can split the initials and name with colon(:) and set the values to the select dropdown and input text box:

var dbValue = 'MR:Raju';
var initials = dbValue.split(':')[0];
var username = dbValue.split(':')[1];
$('#name_with_initials').val(initials);
$('#customername').val(username);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-group">
  <span class="input-group-addon">
    <select name="name_with_initials" id="name_with_initials">
      <option value="MR">MR</option>
      <option value="MRS">MRS</option>
      <option value="MS">MS</option>
      <option value="MASTER">MASTER</option>
    </select>
  </span>
  <input type="text" name="name_with_initials" id="customername" onKeyPress="return ValidateAlpha(event);" class="form-control detailinfo" placeholder="Full Name">
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

@Diamond glad to help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.