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
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
There is many small errors you need to fix before this will work:
You need to add
this
toonclick="btnpressforalias();"
Then you change
btnpressforalias = function()
tobtnpressforalias = function(obj)
, and then uselet address_type = $(obj).val().split(":");
A jQuery object does not have
.value
but instead have.val()
:$(obj).value.split(":")
->$(obj).val().split(":")
You are missing you id(
#
) selector in$('aliastype')
You have a type error – You looking for
$('#aliastype')
but your element is called aliastyp.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
Demo