英文:
SKU validation with jquery
问题
I'm trying to make a validation SKU of this product, showing an alert message. Before, I had the same problem in another situation.
<?php foreach($dvdLists as $key => $dvdList) { ?>
<p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
<?php } ?>
I tried to do the same solution with each function but doesn't work. I need to get each SKU product to make a comparison with the SKU input. Doing this that way I can only get the first one. The second forward doesn't work.
$('#save_product').click(function(e){
var skuInput = $.trim($('#sku').val());
if(skuInput === $('.sku-validator-dvd').text()) {
alert('This sku already exists');
}
});
英文:
I'm trying to make a validation SKU of this product, showing an alert message. Before, I had the same problem in another situation.
<?php foreach($dvdLists as $key => $dvdList) { ?>
<p class="sku-validator-dvd" style="visibility:hidden;"><?= $dvdList->sku ?></p>
<?php } ?>
I tried to do the same solution with each function but doesn't work. I need to get each SKU product to make a comparison with the SKU input. Doing this that way I can only get the first one. The second forward doesn't work.
$('#save_product').click(function(e){
var skuInput = $.trim($('#sku').val());
if(skuInput === $('.sku-validator-dvd').text()) {
alert('This sku already exists');
}
});
答案1
得分: 2
Sure, here is the translated code part:
$('#save_product').click(function(e){
var skuInput = $.trim($('#sku').val());
var skuExists = false;
$('.sku-validator-dvd').each(function() {
if (skuInput === $(this).text()) {
skuExists = true;
}
});
if (skuExists) {
alert('This sku already exists');
}
});
Please let me know if you need any further assistance.
英文:
$('#save_product').click(function(e){
var skuInput = $.trim($('#sku').val());
var skuExists = false;
$('.sku-validator-dvd').each(function() {
if (skuInput === $(this).text()) {
skuExists = true;
}
});
if (skuExists) {
alert('This sku already exists');
}
});
Try this
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论