Click here to Skip to main content
15,347,627 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Proper decoding using Vanilla Javascript Pin
jkirkerx18-Feb-22 6:49
professionaljkirkerx18-Feb-22 6:49 
GeneralRe: Proper decoding using Vanilla Javascript Pin
Richard Deeming24-Feb-22 0:21
mveRichard Deeming24-Feb-22 0:21 
GeneralRe: Proper decoding using Vanilla Javascript Pin
jkirkerx24-Feb-22 5:37
professionaljkirkerx24-Feb-22 5:37 
QuestionAngular JS A href in View source Pin
Member 367124116-Feb-22 1:36
MemberMember 367124116-Feb-22 1:36 
AnswerRe: Angular JS A href in View source Pin
Richard Deeming17-Feb-22 1:58
mveRichard Deeming17-Feb-22 1:58 
QuestionWhy is my last input box not centering (class: powerwall-battery-input)? Pin
WannaBeAWebDev11-Feb-22 14:20
MemberWannaBeAWebDev11-Feb-22 14:20 
AnswerRe: Why is my last input box not centering (class: powerwall-battery-input)? Pin
rnbergren15-Feb-22 3:03
Memberrnbergren15-Feb-22 3:03 
QuestionUsing modules in a regular PHP Web Application - function is undefined Pin
jkirkerx9-Feb-22 12:23
professionaljkirkerx9-Feb-22 12:23 
Well, my idea of using converting my JavaScript into modules, so I have just one copy of every function to manage hit a concrete wall today upon implementing my great idea. Perhaps I'm just overlooking something or it's just not feasible to do.

This is a plain PHP 7.4 project with some Bootstrap 5, Feather Fonts, plain vanilla Javascript. No webpacks or Gulp yet. No compressed code or script. Just a folder called assets that containers all the CSS, Scripts, Images. This PHP project has many includes for Bootstrap Modals, headers, footers, navigation. I'm using PHP Storm from Jet Brains to create with.

Let's start with "must declare type as module" with you use a external script element for a module that has exports. Then make that change from "text/javascript" to "module" and now that error clears, and the new error comes up, "function saveProjectWithProgress() is undefined".

I made a core module, literally called core.module.js, which consolidates all my special functions. This is the whole file.
C#
export { dismissProjectNoticesAsync as dismissProjectNotices } from './projectNoticesModal.module.js';
export { saveVersionNoteAsync as saveVersionNote } from './saveVersionNote.module.js';
export { saveManagerAsync as saveManager } from './saveManagerAsync.module.js';
export { saveSwanJobAsync as saveSwanJob } from './saveSwanJobAsync.module.js';
export { saveCommentAsync as saveComment } from './saveCommentsAsync.module.js';
export { removeCommentAsync as removeComment } from './removeComment.module.js';
export { addFeatureAsync as addFeature, removeFeatureAsync as removeFeature, validateFeatureAsync as validateFeature } from './features.module.js';
export { checkSupplierAsync as checkSupplier } from './checkSupplierAsync.module.js';
export { recalculateAsync as recalculate } from './recalculateProjectAsync.module.js';
export { saveProjectAsync as saveProject } from './saveProjectAsync.module.js';
export { saveProjectWithProgressAsync as saveProjectWithProgress } from './saveProjectWithProgress.module.js';
And my PHP HTML, just a snippet of it.
<button type="Button" onclick="saveProjectWithProgress()">Save</button>
<?php include dirname(DIR, 2) . '/includes/modals/core/confirmSave.modal.php'; ?>
<?php include dirname(DIR, 2) . '/includes/modals/core/projectNotices.modal.php'; ?>
<script type="module" src="/pcad/assets/scripts/core/module/core.module.js"></script>
And the error from the console ....
Uncaught ReferenceError: saveProjectWithProgress is not defined<br />
    onclick <a href="https://core/breakdown/updateBreakdown.phtml:1">https://core/breakdown/updateBreakdown.phtml:1</a><br />
updateBreakdown.phtml:1:1<br />

I understand the error message. I've done this before, but I made a script element, imported the function and ran the function inside the script element, but the concept of importing a function and using it in onclick="udv()" doesn't cut it.
C#
<script>
import { udv } from 'udv';
udv();
</script>
PHPStorm suggested that I wrap the onclick="" with a function ... But this seems strange to me.
<button type="Button" onclick="function saveProjectWithProgress() { } saveProgectWithProgress()">Save</button>
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Using modules in a regular PHP Web Application - function is undefined - Think I got it now Pin
jkirkerx9-Feb-22 13:25
professionaljkirkerx9-Feb-22 13:25 
AnswerRe: Using modules in a regular PHP Web Application - function is undefined Pin
Richard Deeming9-Feb-22 21:49
mveRichard Deeming9-Feb-22 21:49 
GeneralRe: Using modules in a regular PHP Web Application - function is undefined Pin
jkirkerx10-Feb-22 5:00
professionaljkirkerx10-Feb-22 5:00 
GeneralRe: Using modules in a regular PHP Web Application - function is undefined Pin
jkirkerx10-Feb-22 10:52
professionaljkirkerx10-Feb-22 10:52 
QuestionModules and scripts, common modules and scripts, just want to call some functions from a common external script, sort of ES6 Pin
jkirkerx28-Jan-22 10:29
professionaljkirkerx28-Jan-22 10:29 
AnswerRe: Modules and scripts, common modules and scripts, just want to call some functions from a common external script, sort of ES6 Pin
jkirkerx28-Jan-22 10:52
professionaljkirkerx28-Jan-22 10:52 
QuestionArea of ​​a 2d room Pin
Member 1550401118-Jan-22 1:29
MemberMember 1550401118-Jan-22 1:29 
SuggestionRe: Area of ​​a 2d room Pin
Richard MacCutchan18-Jan-22 1:37
mveRichard MacCutchan18-Jan-22 1:37 
QuestionHow to solve this in js Pin
Miraz Uddin17-Jan-22 18:57
MemberMiraz Uddin17-Jan-22 18:57 
AnswerRe: How to solve this in js Pin
Richard Deeming17-Jan-22 21:34
mveRichard Deeming17-Jan-22 21:34 
QuestionHow to solve this in js Pin
Miraz Uddin17-Jan-22 18:53
MemberMiraz Uddin17-Jan-22 18:53 
AnswerRe: How to solve this in js Pin
Richard Deeming17-Jan-22 21:34
mveRichard Deeming17-Jan-22 21:34 
GeneralString Pin
SHAFI CANVASS6-Jan-22 12:40
MemberSHAFI CANVASS6-Jan-22 12:40 
GeneralRe: String Pin
RedDk6-Jan-22 13:07
MemberRedDk6-Jan-22 13:07 
GeneralRe: String Pin
jhonaa11-Jan-22 21:24
Memberjhonaa11-Jan-22 21:24 
QuestionReplecing .data() jQuery with JavaScript Pin
Member 154605438-Dec-21 9:46
MemberMember 154605438-Dec-21 9:46 
AnswerRe: Replecing .data() jQuery with JavaScript Pin
Richard Deeming8-Dec-21 22:12
mveRichard Deeming8-Dec-21 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.