I have the following code:
<div class="checkout-related-view__related-row">
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--left">
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox-7087458-Z22-00025" value="2536" data-role="none">
<label for="related-checkbox-7087458-Z22-00025">
<span class="checkbox"></span>
TV Bed or Adjustable Bed Assembly</label>
</div>
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--right">
<span class="price"><span class="currency">£</span>0</span>
<a href="javascript:void(0)" class="checkout-icon checkout-icon-info related-info" data-toggle="popover" title="" data-content="When your new TV or Adjustable bed is delivered we will take care of all the assembly required, completely free of charge."
data-html="true" data-trigger="focus" tabindex="0" data-original-title="Free Assembly">
<span class="visuallyhidden">Free Assembly</span>
</a>
</div>
<div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--qty">
<div class="input-combobox input-combobox__with-qty" data-label="Qty" data-range-min="0" data-range-max="1">
<span class="input-combobox__label">Qty</span>
<input class="input-combobox__text input-qty" type="text" name="related_products[7087458][2536][qty]" value="0">
</div>
</div>
</div>
I was looking at how can check if the block contains TV Bed or Adjustable Bed Assembly to change the QTY value to "1". So far I've managed to change the value to "1" using the following JS:
document.getElementsByClassName("input-combobox__text input-qty")[2].value = "1";
The issue I am having now is to actually place a logic that will execute the JS only if the "TV Bed or Adjustable bed". I've tried with :contains
but it seems that it didn't work. Can you please help?
The scenario:
2 Products with same classes:
1st is Wood Bed
2nd product is TV Bed
Currently:
If JS catch a label and text that contains TV bed it will apply the QTY of 1 to the first item, regardless it is TV Bed or Wood Bed
End goal:
If TV Bed exist set the QTY as 1 only to the relevant product
Currently I am referring to array and define which QTY to be changed. I also refer to it as ".input-combobox__text.input-qty"
Is there any way how I can target the specific input with name="related_products[7087458][2536][qty]"
Please refer to: https://jsfiddle.net/ckuxzxms/5/