mardi 27 juin 2017

jQuery focus() method not working?

I'm building an Outlook formatter and am having a problem getting the value of the input in the form to display on the copyDiv. It displays everything in theWholeString except for the inputted values. I'm thinking something might be wrong with the focus() method. How can I fix this so that the input is displayed as well? Here's my source code:

$(document).ready(function() {

  var firstName = $("#firstName").val();
  var lastName = $("#lastName").val();

  var lastNameLC = lastName.toLowerCase();
  var firstInitial = firstName.substr(0, 1);
  var firstInitialLC = firstInitial.toLowerCase();
  var firstInitialLast = firstInitial.concat(lastName);

  var theWholeString = "New-RemoteMailbox -Alias " + firstInitialLast + " -Name " + '"' + firstName + " " + lastName + '"' + " -FirstName " + firstName + " -LastName " + lastName + " -DisplayName " + '"' + firstName + lastName + '"' + " -UserPrincipalName " + firstInitialLC + lastNameLC + "@belmont.gov -RemoteRoutingAddress " + firstInitialLC + lastNameLC + "@belmont.gov.onmicrosoft.com -OnPremisesORganizationalUnit ";

  var finalString = "";

  $("#submitButton").click(function() {

    $('input[type="checkbox"]').click(function() {
      if ($(this).prop("checked")) {
        finalString = theWholeString + "blueone.pd/PDUser";
      } else {
        finalString = theWholeString + "belmont.local/BelmontUsers";
      }
    });

    $("#copyDiv").html(finalString).end().appendTo($("body"));
  });

  return false;
});

function changeFocus(id) {
  var v = "#" + id;
  $(v).focus();
}
<script src="http://ift.tt/1oMJErh"></script>
<link href="http://ift.tt/2apRjw3" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<body>
  <div class="container" style="margin-top:120px">
    <div class="row">
      <div class="col-xs-6 col-xs-offset-3">
        <h4>1. Enter name:</h4>
        <form id="nameForm" method="post" action="">
          <div class="form-group">
            <label for="firstName" class="sr-only">First:</label>
            <input class="form-control" id="firstName" name="firstName" type="text" placeholder="First Name" value="" />
          </div>
          <div class="form-group">
            <label for="lastName" class="sr-only">Last:</label>
            <input class="form-control" id="lastName" name="lastName" type="text" placeholder="Last Name" value="" />
          </div>
          <div class="check-box">
            <label for="policeDept">Police Department?</label>
            <input type="checkbox" id="pdCheck" data-group-cls="btn-group-sm">
          </div>
          <button class="btn btn-primary pull-right" id="submitButton" type="button" value="Submit" />Make </button>
        </form>
      </div>
      <div class="row">
        <div class="col-xs-6 col-xs-offset-3">
          <h4>2. Copy this text:</h4>
          <div id="copyDiv" class="panel panel-default" style="padding:10px">Result
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
<script src="http://ift.tt/2aHTozy" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>



Aucun commentaire:

Enregistrer un commentaire