skip to Main Content

I got a question, I´m building a website which can be startete via powershell.
The PowerShell HTML code is this:

$proxys = ""
foreach ($email in $ADObj.proxyAddresses){
$proxys += "<button id='$email' name='alias' type='button' class='list-group-item list-group-item-action' data-bs-toggle='modal' data-bs-target='#EditAlias' value='$email' onclick='btnpressforalias();'> $email </button>"
}

my HTML code is:

[...]
<script>
var btnpressforalias = function () {
let address_type = $(this).value.split(":");
if(address_type[0] == "SMTP") {$('aliastype').val('aliastyp_primary_mail').change();}
if(address_type[0] == "smtp") {$('aliastype').val('aliastyp_alias_mail').change();}
if(address_type[0] == "SIP") {$('aliastype').val('aliastyp_primary_sip').change();}
if(address_type[0] == "sip") {$('aliastype').val('aliastyp_alias_sip').change();}
if(address_type[0] == "x500") {$('aliastype').val('aliastyp_x500').change();}
if(address_type[0] == "notes") {$('aliastype').val('aliastyp_notes').change();}
let address = address_type[1].split("@");
document.getElementById('aliasaddress_local').value = address[0];
};
</script>
[...]
<button id="smtp:[email protected]" name="alias" type="button" class="list-group-item list-group-item-action" data-bs-toggle="modal" data-bs-target="#EditAlias" value="smtp:[email protected]" onclick="btnpressforalias();">smtp:[email protected]</button>
[...]
<div class="input-group">
<select id="aliastyp" name="aliastyp" class="form-select col-sm-2">
<option id="aliastyp_primary_mail" value="SMTP">SMTP</option>
<option id="aliastyp_alias_mail" value="smtp">smtp</option>
<option id="aliastyp_primary_sip" value="SIP">SIP</option>
<option id="aliastyp_alias_sip" value="sip">sip</option>
<option id="aliastyp_x500" value="x500">x500</option>
<option id="aliastyp_notes" value="notes">notes</option>
</select>
<input type="text" id="aliasaddress_local" name="aliasaddress_local" class="form-control col-sm-6" onkeyup="this.value=this.value.replace(/[^a-z0-9 .]/gi, '');">
<select class="form-select col-sm-2" id="primarysmtpaddress_accepteddomain" name="primarysmtpaddress_accepteddomain">
<!-- {row_ad} -->
</select>
</div>

By button press the modal comes up, but the Selected type nor the text get into the inbox. What I dont see?

I tried serveval different "versions" of the jquery script but nothing helps 🙁

2

Answers


  1. Chosen as BEST ANSWER

    The answer was the missing include of js. I downloaded and included the newest version and the script worked. Everything is perfect, thanks to @Carsten Løvbo Andersen


  2. There is many small errors you need to fix before this will work:

    1. You need to add this to onclick="btnpressforalias();"

    2. Then you change btnpressforalias = function() to btnpressforalias = function(obj), and then use let address_type = $(obj).val().split(":");

    3. A jQuery object does not have .value but instead have .val() : $(obj).value.split(":") -> $(obj).val().split(":")

    4. You are missing you id(#) selector in $('aliastype')

    5. You have a type error – You looking for $('#aliastype') but your element is called aliastyp.

    6. You need to set the value of the select, not the id – $('aliastype').val('aliastyp_primary_mail') -> $('aliastype').val('SMTP')

    Last I would advice you, if possible, not to mix javascript and jQuery.
    $('#aliasaddress_local').val(address[0]);

    Modified code

    var btnpressforalias = function(obj) {
      let address_type = $(obj).val().split(":");
      if (address_type[0] == "SMTP") {
        $('#aliastype').val('SMTP').change();
      }
      if (address_type[0] == "smtp") {
        $('#aliastype').val('smtp').change();
      }
      if (address_type[0] == "SIP") {
        $('#aliastype').val('SIP').change();
      }
      if (address_type[0] == "sip") {
        $('#aliastype').val('sip').change();
      }
      if (address_type[0] == "x500") {
        $('#aliastype').val('x500').change();
      }
      if (address_type[0] == "notes") {
        $('#aliastype').val('notes').change();
      }
      let address = address_type[1].split("@");
      document.getElementById('aliasaddress_local').value = address[0];
    };
    

    Demo

    var btnpressforalias = function(obj) {
      let address_type = $(obj).val().split(":");
      if (address_type[0] == "SMTP") {
        $('#aliastype').val('SMTP').change();
      }
      if (address_type[0] == "smtp") {
        $('#aliastype').val('smtp').change();
      }
      if (address_type[0] == "SIP") {
        $('#aliastype').val('SIP').change();
      }
      if (address_type[0] == "sip") {
        $('#aliastype').val('sip').change();
      }
      if (address_type[0] == "x500") {
        $('#aliastype').val('x500').change();
      }
      if (address_type[0] == "notes") {
        $('#aliastype').val('notes').change();
      }
      let address = address_type[1].split("@");
      document.getElementById('aliasaddress_local').value = address[0];
    };
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <button id="smtp:[email protected]" name="alias" type="button" class="list-group-item list-group-item-action" data-bs-toggle="modal" data-bs-target="#EditAlias" value="smtp:[email protected]" onclick="btnpressforalias(this);">smtp:[email protected]</button>
    
    <div class="input-group">
      <select id="aliastype" name="aliastyp" class="form-select col-sm-2">
        <option id="aliastyp_primary_mail" value="SMTP">SMTP</option>
        <option id="aliastyp_alias_mail" value="smtp">smtp</option>
        <option id="aliastyp_primary_sip" value="SIP">SIP</option>
        <option id="aliastyp_alias_sip" value="sip">sip</option>
        <option id="aliastyp_x500" value="x500">x500</option>
        <option id="aliastyp_notes" value="notes">notes</option>
      </select>
      <input type="text" id="aliasaddress_local" name="aliasaddress_local" class="form-control col-sm-6" onkeyup="this.value=this.value.replace(/[^a-z0-9 .]/gi, '');">
      <select class="form-select col-sm-2" id="primarysmtpaddress_accepteddomain" name="primarysmtpaddress_accepteddomain">
        <!-- {row_ad} -->
      </select>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search