Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(