Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

Metronic, jQuery, get value from input field, error, undefined


Hi,

I just want to alert user when user input some data in input field, for example

https://preview.keenthemes.com/metronic8/demo35/apps/ecommerce/catalog/edit-category.html

in input field Category name. So I added simple script at the bottom of the page, like this,

<!--end::Custom Javascript-->
<script>
alert($('#category_name').val());
</script>
<!--end::Javascript-->

But I got an error "undefined"

What is going on? How can I get value from input field?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (7)


Great, it works now. Thank you a lot.



Hi,

Please try to run your code in


KTUtil.onDOMContentLoaded(function() {
// your code
});


Or


window.onload = (event) => {
// your code
};


Regards,
Sean

Regards,
Sean



Hi,
It works if I do as you said when form is as html page. But if the form is in the modal, it reports the same error again even if I do as you said.
"undefined"



Hi,

Inside modal you can use:


<script>
window.addEventListener("load", () => {
/// your code
});
</script>


Can you try this ? If any error is shown please share your error viahttps://imgur.com/

Regards,
Sean


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(