0

I am new to LWC and trying to translate an existing VF page into LWC. I am trying to call an onclick function (pretty simple) but the function is not firing. Can anyone help me troubleshoot why this onclick isn't calling my function?

LWC html page:

<div class="col-xs-8">
                    <input id="arcNumber-input" type="text" class="form-control" value={arcNumberInput}/>

                </div>
                <div class="col-xs-4">
                    <input type="submit" class="btn action-item tertiary w-margin uppercase-font"
                            id="arcNumber-submit" value={label.Sip_Common_Submit}
                            onclick={submitArcNumber}/>
                </div>

I then have a function in my LWC js controller as follows:

arcNumberInput = '';
submitArcNumber() {
    console.log(arcNumberInput);
}

However when I click the button, nothing is logged in the console. Is it because I'm using a standard input element and not lightning input? Thanks

1 Answer 1

2

arcNumberInput needs to be preceded by this => this.arcNumberInput , otherwise the invocation won't work, and you will see something similar to variable x has not been declared or is undefined

4
  • Okay I see now that the function is being called and nothing is logged because there is no "this." in front of arcNumberInput like you mentioned, however arcNumberInput is still blank when I input something and click submit. Since the submit button is firing the event, exploring the event.target.value just returns the text on the button ("Submit"). How can I get the value of arcNumberInput from the first input element? Thanks Jul 13, 2021 at 18:54
  • to avoid extended discussions and keep 1 post / 1 answer, please open a new question and make sure to accept answers so posts are marked as resolved
    – glls
    Jul 13, 2021 at 18:57
  • I think the underlying question is still unanswered, adding "this." to arcNumberInput is not displaying the arcNumberInput value. It is still blank Jul 13, 2021 at 19:44
  • your question states that the function is not firing (or wasn't) - the root cause was because of the missing this. Can anyone help me troubleshoot why this onclick isn't calling my function so, it is normal that nothing is logged to the console due to the above. now, if your console log outputs an empty string, and you cant seem to figure that out, it is a different question, with a different answer. Just want to avoid addressing multiple errors/issues in the post. the format here is, 1 question 1 answer.
    – glls
    Jul 13, 2021 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.