1

Im Looking for a way to search for a string inside a text and get the value behind it. Sorry, I am very bad at JS.

The text I'm using:

<label for="sample-group-15822160-0"><br>
<input name="sample-group-15822160" id="sample-group-15822160-0" value="option-1" numbercount="1" type="radio" checked="checked">Option 1</label>

What I need: 1

-> So just the value from the numbercount field inbetween the ".

What I tried:

var numhelper = sampleButtonObjects[index].outerHTML;
    var numhelperNum = ico1helper.split('numbercount="')[0].split('"')[1].trim();
                    var num = numhelperNum ;

What I received: sample-group-15822160-0 (the ID).

Can somebody please tell me, what I'm doing wrong? Thank you!

2
  • Can you not target the input's numbercount attribute directly? Seems like an XY Problem. Commented Feb 20, 2020 at 16:37
  • Why are you not just reading the attribute? Commented Feb 20, 2020 at 16:37

1 Answer 1

2

You did all good except this tiny error

ico1helper.split('numbercount="')[0].split('"')[1].trim()
                                  ^             ^

The indices must be 1 & 0 in order to work

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you so much Pavitra. And the way you told me (you did all good"), made me feel good. So you're my hero for today :) But, could you please explain me the difference, so that I would better understand in the future (I try to learn, not just to copy & paste) Thank you :)
If you give me 15 minutes, I can visualise this for you :)
@ThomasB Go to these pages and run "Visualize Execution" button
You're awesome Pavitra. Thank you so much and have a great day!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.