CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: What is JS proposal  (Read 440 times)

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1029
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: What is JS proposal
« Reply #15 on: 12 Aug 2023, 09:28:53 pm »
Technically those double quotes aren't needed anymore, but in the old days for IE's JScript "submit" was a reserved word despite lacking a matching object or property of window.

Today since we don't care about IE, yeah you could lose those. Force of habit I've not broken myself of.

The current list of words you'd HAVE to put in quotes is here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #16 on: 12 Aug 2023, 09:53:48 pm »
Thanks for the lesson.... :)  i hate IE too and dont ever use it, i wish i could remove it.   

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #17 on: 12 Aug 2023, 11:46:54 pm »
I am getting this error

Quote
js_sbcshare.js:79 Uncaught Error: #share_checkbox not found, halting script
    at getOrWarn (js_sbcshare.js:79:39)
    at js_sbcshare.js:97:32

at first i thought it was because you had  share_Checkbox and shareCheckbox  and shareSubmit and i think those shoud be share_checkbox and share_submit and then also i noticed there is  share.checkbox.addEventListener and i think it should be share_checkbox

but i am still getting that error and i dont know why... its there, i tried moving the call in the footer inside a event listener but that did not work either.   not sure why its not seeing it...

do you want all the code i currently have, will that help?


Update:  i put this right above const in the code and it says its null so ill find out why that is so.   I could not put it after const because it told me error missing ;  and expected identifier, maybe because its inside the const.    Anyway ill update this when i find out why its null...

Code: [Select]
var cb = document.getElementById('share_checkbox');
           
console.log(cb);

« Last Edit: 13 Aug 2023, 04:47:32 am by durangod »

GrumpyYoungMan

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +8/-0
    • Grumpy Young Man
Re: What is JS proposal
« Reply #18 on: 13 Aug 2023, 04:11:38 am »
I am getting this error

Quote
js_sbcshare.js:79 Uncaught Error: #share_checkbox not found, halting script
    at getOrWarn (js_sbcshare.js:79:39)
    at js_sbcshare.js:97:32

at first i thought it was because you had  share_Checkbox and shareCheckbox  and shareSubmit and i think those shoud be share_checkbox and share_submit and then also i noticed there is  share.checkbox.addEventListener and i think it should be share_checkbox

but i am still getitng that error and i dont know why... its there, i tried moving the call in the footer inside a event listener but that did not work either.   not sure why its not seeing it...

do you want all the code i currently have, will that help?


Update:  i put this right above const in the code and it says its null so ill find out why that is so.   I could not put it after const because it told me error missing ;  and expected identifier, maybe because its inside the const.    Anyway ill update this when i find out why its null...

Code: [Select]
var cb = document.getElementById('share_checkbox');
           
console.log(cb);

Have you assigned it as an html Id (#) and not a class (.)?

The HTML to the actual page may help?
Trying to learn a new trick to prove old dogs can learn new ones...

Total Novice have-a go Amateur Programmer - not sure that is the right thing to say... but trying to learn...

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #19 on: 13 Aug 2023, 04:39:39 am »
yep thats the first thing i checked is to be sure it was an id, i also checked in css to be sure as well not that the css would matter so much but i did check it.   Im still waking up so just now looking into it.  All i can think of at the moment is that its trying to load the file in the footer before the dom is finished loading.

in the footer i have this
Code: [Select]
<script src="core/js/js_sbcshare.js"></script>


Here is the html

Code: [Select]
  <!-- shareit  modal -->

  <!-- no text editor on this form intentionally -->

  <div id="shareit" class="modal modalMenu">
<!-- <a href="" class="modalClose" hidden aria-hidden="true"></a> -->
<div> <!-- start no name -->
  <nav>
<h2>Web Share &nbsp; <span class="moveright"><a href="" onClick="close();"><span class="smalltxt"><?= htmlspecialchars(getLangValue('GENERAL_CLOSE_TEXT')); ?> <i class="far fa-times-circle"></i></span></a></span></h2>
<div  class="scroll_it">
<div> <!-- noname two start -->
  <ul>
   <li>
         <form name="shareit_form" id="shareit_form">
              <section>
                 <label for="share_title">Title: (read only)</label>
                 <br>
                 <input type="text" name="share_title" id="share_title" value="" size="40" readonly>
                 <br>
                 <label for="share_url">URL: (read only)</label>
                 <br>
                 <input type="url" name="share_url" id="share_url" value="" size="50" readonly>
                 <br>
                 <label for="share_content">Optional Message: Max <?= SBC_TEXTAREA_CHAR_LIMIT; ?>  chars</label>
                 <br>
                 <textarea class="mceNoEditor"  name="share_content" id="share_content" maxlength="<?= SBC_TEXTAREA_CHAR_LIMIT; ?>" placeholder="Optional Share Content - Reminder never share personal data!" onKeydown="return noEditor_charsLeft('share_content');"  onBlur="this.value = text_clean(this.value);"></textarea>
                 <br>
                 <div id="share_content_counter"></div>
                 
                 <div class="auth_share">
                   <label for="share_checkbox">Authorize:</label>
                   <br>
                   <input type="checkbox" name="share_checkbox" id="share_checkbox" value="" required>
                   <span class="share_cb">Check this box to authorize this share. Button disabled until box is checked.</span>
                 </div> <!-- auth_share -->
                 
                 <?php
                 
                   
//no token or hpot used as it is all done by js
                   
                  
?>

                 
               
                 <input type="submit" id="share_submit" name="share_submit" value="Submit" disabled>
                 <br>
                 <br>
                 <div id="share_disclaimer">
                 <p>Disclaimer: This feature is intended to allow you to share topics and other information you feel others
                 might also enjoy or get value from. It is not intended to share any kind of personal information which could put you or others
                 in danger.  Please never share any kind of personal identifiable or sensitive information using this feature. You hold harmless
                 <?= SITE_NAME; ?>, its employees and all associates from any damage, harm, or event(s) which may occur as a result of this topic post.</p>
                 
                 <p> The data currently used in this feature only contains a title and a url. Both are read only fields and require
                 no input from you. The text message part of this feature is optional and you are not required to enter anything into the message field.</p>   
                 </div>
               </section>
          </form>
    </li> 
   </ul>
      </div> <!-- noname two end -->
    </div> <!-- scroll it -->
  </nav>
    </div> <!-- end no name -->
</div> <!-- sharit.modal.menu -->



and the css just to share

Code: [Select]
/* shareit code */


#shareit > div > nav {
    width: 60em;
    max-width: 60em;
}


form#shareit_form {
    width: 100%;
}


#shareit .scroll_it {
    background-color: #d2cbcb; /* off white */
    padding: 0 3em 0 3em;
}


#share_submit {
    float: right;
    line-height: 1em;
    margin-top: 1em;
    width: 7em;
    font-size: 1em;
}


#share_submit[disabled] {
     cursor:not-allowed;
}

input#share_title,
input#share_url,
input#share_content {
    margin-bottom: 1em;
}


textarea#share_content {
    height: 6em;
    width: 100%;
    word-break: break-word;
    overflow-y: auto;
    overflow-x: hidden;
    resize: both;
}


.auth_share {
    width: 100%;
    height: 6em;
    border: 0.063em solid #000000;
    padding: 0.25em;
}

#share_checkbox {
    display: inline-block;
    font-size: 1.75em;
    float: left;
    margin: 0 0.25em;
}

.share_cb {
    display: block;
    font-size: 1em;
    margin-top: 1em;
    font-weight: bold;
}

#share_disclaimer {
    margin-top: 1em;
    font-size: 0.75em;
}


/* it will be one of these */
/* depending of if editor or not  */

#share_content_counter {
    font-size: 1em;
    margin-bottom: 0.75em;
}

#share_content_countdown {
    font-size: 1em;
    margin-bottom: 0.75em;
}



Update:  i might be on to something here, seems that the home index page has the error but the blog page does not and the checkbox has value in the blog page, the blog page uses the share feature but the index does not.  So the js code is loading but since the form is not on every page then on the index it fails because there is no form.

Update:   i changed the console log to show value

Code: [Select]
ementById('share_checkbox');
console.log(cb.value);

and it shows input#share_checkbox   on the blog page but null on the index page..   I wish my brain would wake up, i know it has to be something simple i am over looking.

Do i only need to load the js on certain pages that have the feature?

SOLVED :)    yep that was it....   something else i didnt think about.   i fixed it like this in the footer


so far only these pages use that feature, and since i already have a php var for pagename why not use it lol

Code: [Select]

 <?php
  
  $pnames 
= ['blog''forum''video''gallery'];
  
  if(
in_array($pagename$pnames))
  {
   
?>

   
    <script src="core/js/js_sbcshare.js"></script>
 
  <?php    
  
}//close if
  
?>


« Last Edit: 13 Aug 2023, 05:21:09 am by durangod »

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #20 on: 13 Aug 2023, 05:31:21 am »
Ok new challenge.   Should there be a return at the end of the success js part to close it out.  After it sends it closes the modal form but then opens up a new blank modal form with nothing in it, all fields blank.  Why would it open up another one after closing the first one?  That is why i was thinking some kind of return, but i could be wrong.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1029
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: What is JS proposal
« Reply #21 on: 13 Aug 2023, 08:24:11 am »
Is the location hash still pointed at the modal?
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #22 on: 13 Aug 2023, 08:32:21 am »
Is the location hash still pointed at the modal?

foregive me for sounding stupid but i dont know what a location hash is.  I know what a hash is but what is the location part, is that the part of the anchor ?   if so here is what i have

Code: [Select]
<!-- share -->
                <a href="#shareit" onClick="setShareValues('share_title','share_url','<?= htmlspecialchars(ucwords($bval['blog_title']), ENT_QUOTES, 'UTF-8'); ?>',
                                          '<?= URL_BASE; ?>blog_view.php?bid=<?= (int) $bval['blog_id']; ?>');"><i class="fas fa-share-alt" title="Share"></i></a> 


and then the setSharValues is this

Code: [Select]
/* used globally for sharing */ 
  /* share_title_id = share form input id we want to set */
  /* share_url_id   = share form input id for url data we want to set  */
  /* title = text title value */
  /* url = url value - be sure it is the full url including https */
  /* these values should be sanitized before arriving here */
   
  function setShareValues(share_title_id, share_url_id, title, url)
  {
        document.getElementById(share_title_id).value=title;
        document.getElementById(share_url_id).value=url;
       
  }//close function setShareValues






durangod

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-0
  • Weebles Wobble - but they dont fall down!
Re: What is JS proposal
« Reply #23 on: 14 Aug 2023, 01:39:32 am »
ok if you mean the address bar then yes here is the address bar info after it loads a blank modal on the page.  This happens right after i close the share box (meaning the actual share feature box with the connections)

im sharing a blog this time

Quote
https://example.com/mysite/blog.php?share_title=Strange+Blog&share_url=https%3A%2F%2Fexample.com%2Fmysite%2Fblog_view.php%3Fbid%3D11&share_content=&share_checkbox=&share_submit=Submit#shareit


but a completely empty form...  why it reopens it i dont know.

Oh by the way just FYI in case you wondered,  I did the open and close {} around the return because the editor told me "no access to try using return"   so i just added the brackets to isolate the return and it accepted it.
« Last Edit: 14 Aug 2023, 01:44:07 am by durangod »

 

SMF spam blocked by CleanTalk

Advertisement