Note that there are some explanatory texts on larger screens.

plurals
  1. POelement selection with prototype js
    primarykey
    data
    text
    <p>I'm having a some problems with a page where I have an input to take product EAN code and compare that to a table listing of products and update the input box with id <code>ean_xxxx</code> to <code>oldValue+1</code>. My current code looks like this:</p> <pre><code>function updateProductQty(ean) { var inputs = document.getElementsByTagName("input"); for (var i = 0; i &lt; inputs.length; i++) { if(inputs[i].id == "ean_" + ean) { inputs[i].value = Number(inputs[i].value) + 1; } } } </code></pre> <p>That I call with this code on the input for EAN-code <code>onchange="updateProductQty(this.value);"</code></p> <p>Now the problem is that the input box with ID <code>ean_xxxxx</code> is located inside a table row, and I also need to compare to a value in a previous TD-tag. The value I'm looking for is surrounded by HTML like this:</p> <pre><code>&lt;td&gt; &lt;h5 class="title"&gt;....&lt;/h5&gt; &lt;div&gt;&lt;strong&gt;...&lt;/strong&gt; A252502&lt;/div&gt; &lt;dl class="item-options"&gt; &lt;dt&gt;...&lt;/dt&gt; &lt;dd&gt;..&lt;/dd&gt; &lt;/dl&gt; &lt;/td&gt; .... more &lt;td&gt;-tags &lt;td&gt; ... &lt;input id="ean_xxxx" .... /&gt; ... &lt;/td&gt; </code></pre> <p>As you can see, when I locate the input tag, I never know which row in the table I'm at, and the value I want to add a check for is "A252502".</p> <p>The site uses Prototype as js framework, which I have no experience in what so ever, so I mostly use basic JS where Google fails me for Prototype solutions.</p> <p>If only I could get the TD contents, I could strip the -tag and any spaces to get the value - but how can search for it? I can't even step back in the DOM tree, because I either get the EAN code or this internal article ID, not both. So no <code>inputs[i]</code> to start out from. Any help is highly appreciated, no matter if it's in Prototype syntax or basic JS.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload