Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:28:13+00:00 2026-05-31T07:28:13+00:00

Here is functioning code on a form that displays a Tweet button — the

  • 0

Here is functioning code on a form that displays a Tweet button — the button’s on a form that displays several images — when the user clicks one of the images, it becomes the ‘selected’ image and the Tweet button is supposed to tweet the selected image’s name and url:

      <a id="tweetBtnId" href="https://twitter.com/share" class="twitter-share-button" 
         data-text="Check me out on OurWebSite!"
         data-url=http://$ourSiteURL
         data-via=http://$ourSiteURL data-size="medium" data-count="none">Tweet</a>
     <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0]; 
            if(!d.getElementById(id)){js=d.createElement(s); js.id=id; 
              js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js,fjs);}}
                (document,"script", "twitter-wjs");</script>   

I have an ‘onclick()’ handler for the div that displays the image. When the user clicks one of the images, its div’s onclick() handler is called and sets that image to be the ‘currentlySelectedImage’ on the page — and the onclick() handler then needs to update the Tweet button’s ‘data-text’ attribute with the name of the just-selected image:

          // This is part of the code of the 'onclick()' handler for
          // the image being selected. 
         <script> 
         function handleImageOnClick()
         {
           var myDynamicTweetText = "name of currently-selected image goes here";
           var elem = document.getElementById("tweetBtnId");
           alert("The elem is: " + elem);  // elem IS NULL !!  Dagnabbit.

           // this fails because 'elem' is null
           elem.setAttribute("data-text", myDynamicTweetText);

           // other onclick() code not shown for brevity......
         }
         </script>

I need to dynamically change the ‘data-text’ attribute’s value in the Tweet button to be the name of the selected image. I added the javascript code above which fails– the ‘elem’ obtained from the code here:

    var elem = document.getElementById("tweetBtnId");

is null (I think) because of this line in the Twitter tweet button code above:

   if(!d.getElementById(id)){js=d.createElement(s); js.id=id;

I’m not sure but it looks like the Twitter Tweet button default script overwrites any attempt
to add an ‘id’ attribute to the Tweet button.

You will see that I added the id=”tweetBtnId” to the Tweet button above so I could get access to the Tweet button in my image-selection onclick() handler above, then set the ‘data-text’ to the name of the just-selected image.

I just doubt that Twitter’s design goal for the Tweet button was “we’re gonna dumb this sucker WAY down, we’ll only let these animals choose ONE data-text value – every Tweet button has to have one hard-coded, “Once-on-the-page” data-text attribute – joke’s on them if they try to dynamically change the Tweet button’s data-text attribute.”

I need to get this to work — any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:28:14+00:00Added an answer on May 31, 2026 at 7:28 am

    Looks like it’s going to be the kludgy hidden form/php variable approach for now — I’ll post back if I find a better work-around.

    EDIT: the hidden-form/PHP variable solution has beaten the roadblock put up by Twitter’s Tweet button — I can now successfully, dynamically change the Tweet button text at will, anytime based on the user’s client-side input. Per Domenic’s astute observation that the question above is too long and has code in it, I’ll skip posting the answer here, and I apologize for the length above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My working code here correctly put the Tweet button on the page and allows
Here is the form that is inside index.php -- I'm trying to programmatically submit
A form on my website is not functioning correctly in Safari/Chrome. When a user
Here's the deal: I'm in the process of planning a mid-sized business application that
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
I'm using a button to slideToggle the display of my disclaimer here, and for
I have a code that does compression, encryption and checksum on a File Outputstream.
I have a form with a text input box which displays similar entries to
Background: I followed the tutorial here to setup a polymorphic User favorites data model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.