0

I have the following html structure:

<div class="checkout-related-view__related-row last">
  <div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--left">
    <input class="checkbox related-checkbox" data-role="none" id="related-checkbox-7085508-020-01077" type="checkbox" value="10">
    <label for="related-checkbox-7085508-020-01077"><span class="checkbox"></span> Old Bed or Mattress Recycling</label>
  </div>
  <div class="checkout-related-view__related-row-cell checkout-related-view__related-row-cell--right">
    <span class="price"><span class="currency">£</span>39</span> <a class="checkout-icon checkout-icon-info related-info" data-content="We will collect your old bed frame, mattress, divan base and headboard, and recycle as much as possible into new material."
    data-html="true" data-original-title="Recycling Service" data-toggle="popover" data-trigger="focus" href="javascript:void(0)" tabindex="0" title=""><span class="visuallyhidden">Recycling Service</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-max="1" data-range-min="0">
      <span class="input-combobox__label">Qty</span>
      <input class="input-combobox__text input-qty" name="related_products[7085508][10][qty]" type="text" value="0">
    </div>
  </div>
</div>

I've try using JS to change the QTY. Unfortunatelly there is no luck. Please note that the code has no ID. Is there any way how I can set the value using name or class?

The code I've tried and didn't work is :

document.getElementsByClassName("input-combobox__text input-qty").value="1";

Can you please help?

6
  • Rather than showing code that is working, can you show the code that isn't working that you've tried so we can help fix it? There are any number of ways of setting the value - let's help fix your approach. Commented Jan 14, 2016 at 10:03
  • 2
    there is no elements in this snippet with id = 'related-checkbox-7085601-020-01077' Commented Jan 14, 2016 at 10:04
  • There is no jquery in this question. Why tag with jquery? Commented Jan 14, 2016 at 10:07
  • Why should the quantity change? There doesn't seem to be any indication in the code that it should Commented Jan 14, 2016 at 10:08
  • @ND Yep - I suggest you remove the part about setting checkboxes if it's working for you. It's not the problem you're having, and it seems to be confusing the issue. Commented Jan 14, 2016 at 10:09

2 Answers 2

1

getElementsByClassName returns an array of elements, and you can't apply value to an array. Instead, grab the first item in the returned array:

document.getElementsByClassName("input-combobox__text input-qty")[0].value = "1";
Sign up to request clarification or add additional context in comments.

Comments

1

document.getElementsByClassName returns an array of elements, if you want to set the value of the first match do so

document.getElementsByClassName("input-combobox__text input-qty")[0].value="1";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.