{"id":182,"date":"2009-12-21T12:23:07","date_gmt":"2009-12-21T19:23:07","guid":{"rendered":"https:\/\/www.artisticimposter.com\/blog\/?p=182"},"modified":"2009-12-21T12:23:07","modified_gmt":"2009-12-21T19:23:07","slug":"changing-web-page-items-using-javascript","status":"publish","type":"post","link":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/","title":{"rendered":"Changing Web Page Items Using JavaScript"},"content":{"rendered":"<p>I recently had a client who wanted a page with a SWF movie that could be changed to a different SWF by clicking on a button on the page. A while back, I did a project where the user could click a link and change the source of an image on the page using JavaScript, but changing an entire SWF seemed a little more difficult. The code to change the image to a different image looked like this:<\/p>\n<p class=\"codeformat\">&lt;image id=&#8221;imagetochange&#8221; src=&#8221;pic1.jpg&#8221;&gt;<br \/>\n&lt;a href=&#8221;#&#8221; onclick=&#8221;imagetochange.src=&#8217;pic2.jpg'&#8221;&gt;Change image&lt;\/a&gt;<\/p>\n<p>This code was simple enough, so I tried modifying it to change the source of the SWF when I clicked the link. My code now looked like this:<\/p>\n<p class=\"codeformat\">&lt;object id=&#8221;changemovie&#8221; type=&#8221;application\/x-shockwave-flash&#8221; data=&#8221;flashmovie1.swf&#8221; width=&#8221;640&#8243; height=&#8221;400&#8243;&gt;<br \/>\n&lt;param id=&#8221;changethis&#8221; name=&#8221;movie&#8221; value=&#8221;flashmovie1.swf&#8221; \/&gt;<br \/>\n&lt;\/object&gt;&lt;a href=&#8221;#&#8221; onclick=&#8221;changemovie.data=&#8217;flashmovie2.swf&#8217;; changethis.value=&#8217;flashmovie2.swf&#8217;;&#8221;&gt;Change movie&lt;\/a&gt;<\/p>\n<p>This worked in some browsers but it didn&#8217;t work in others, so I was forced to come up with a different solution. After some research, I was reminded of two JavaScript items that eventually made the whole thing possible: getElementById and innerHTML. After some tweaking, I ended up with a code that looked something like this:<\/p>\n<p class=\"codeformat\">&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nfunction changeText() {<br \/>\ndocument.getElementById(&#8216;flashitem&#8217;).innerHTML = &#8216;&lt;object type=&#8221;application\/x-shockwave-flash&#8221; data=&#8221;flashmovie2.swf&#8221; width=&#8221;640&#8243; height=&#8221;400&#8243;&gt; &lt;param name=&#8221;movie&#8221; value=&#8221;flashmovie2.swf&#8221; \/&gt; &lt;\/object&gt;&#8217;;<br \/>\n}<br \/>\n&lt;div id=&#8221;flashitem&#8221;&gt;<br \/>\n&lt;object type=&#8221;application\/x-shockwave-flash&#8221; data=&#8221;flashmovie1.swf&#8221; width=&#8221;640&#8243; height=&#8221;400&#8243;&gt;<br \/>\n&lt;param name=&#8221;movie&#8221; value=&#8221;flashmovie1.swf&#8221; \/&gt;<br \/>\n&lt;\/object&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;a href=&#8221;#&#8221; onclick=&#8221;changeText();&#8221;&gt;Change movie&lt;\/a&gt;<\/p>\n<p>First, I created a JavaScript function called changeText(). Inside the function, I placed &#8220;document.getElementByID(&#8216;flashitem&#8217;)&#8221;. This calls a function which searches the page for an element with the id of &#8220;flashitem&#8221;. Then I added &#8220;.innerHTML&#8221;, which tells the program that we are doing something with the innerHTML property of the specified element. I then set the value of the innerHTML property to the code for the SWF object I wanted to replace the original SWF, and closed the changeText() function. Now when the function is called, it will change the HTML inside a div with the id of &#8220;flashitem&#8221; to the code to place the new SWF on the Web page. Now I just needed to create the div and the link.<\/p>\n<p>I created a new div with the code for the original SWF object inside and gave the div an id of &#8220;flashitem&#8221;. Outside the div, I then created a link to call the function changeText(), and it worked perfectly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had a client who wanted a page with a SWF movie that could be changed to a different SWF by clicking on a button on the page. A while back, I did a project where the user could click a link and change the source of an image on the page using JavaScript, &hellip; <a href=\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Changing Web Page Items Using JavaScript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49,42],"tags":[46,41,43],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-javascript-tutorials","category-tutorials","tag-javascript","tag-tips","tag-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Changing Web Page Items Using JavaScript | Artistic Imposter Design<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Changing Web Page Items Using JavaScript | Artistic Imposter Design\" \/>\n<meta property=\"og:description\" content=\"I recently had a client who wanted a page with a SWF movie that could be changed to a different SWF by clicking on a button on the page. A while back, I did a project where the user could click a link and change the source of an image on the page using JavaScript, &hellip; Continue reading &quot;Changing Web Page Items Using JavaScript&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Artistic Imposter Design\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/artisticimposter\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/kbwashburn\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-21T19:23:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/title.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"275\" \/>\n\t<meta property=\"og:image:height\" content=\"82\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Brad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bradwashburn\" \/>\n<meta name=\"twitter:site\" content=\"@bradwashburn\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\"},\"author\":{\"name\":\"Brad\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/2204a26e0617b620cb00fdb1d0111660\"},\"headline\":\"Changing Web Page Items Using JavaScript\",\"datePublished\":\"2009-12-21T19:23:07+00:00\",\"dateModified\":\"2009-12-21T19:23:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\"},\"wordCount\":473,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#organization\"},\"keywords\":[\"JavaScript\",\"Tips\",\"Tutorials\"],\"articleSection\":[\"JavaScript\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\",\"url\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\",\"name\":\"Changing Web Page Items Using JavaScript | Artistic Imposter Design\",\"isPartOf\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#website\"},\"datePublished\":\"2009-12-21T19:23:07+00:00\",\"dateModified\":\"2009-12-21T19:23:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.artisticimposter.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Changing Web Page Items Using JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#website\",\"url\":\"https:\/\/www.artisticimposter.com\/blog\/\",\"name\":\"Artistic Imposter Design\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.artisticimposter.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#organization\",\"name\":\"Artistic Imposter Design\",\"url\":\"https:\/\/www.artisticimposter.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/cropped-logo.png\",\"contentUrl\":\"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/cropped-logo.png\",\"width\":512,\"height\":512,\"caption\":\"Artistic Imposter Design\"},\"image\":{\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/artisticimposter\",\"https:\/\/x.com\/bradwashburn\",\"https:\/\/www.instagram.com\/artisticimposterdesign\/\",\"https:\/\/www.linkedin.com\/company\/artistic-imposter-design\",\"https:\/\/www.youtube.com\/channel\/UC_SGOHbnI9Cy7byzKbQCFlA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/2204a26e0617b620cb00fdb1d0111660\",\"name\":\"Brad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2bddfdea63dd2fdf76c199b2a705d0c374dbd6013cd40dedbc25663d4837e381?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2bddfdea63dd2fdf76c199b2a705d0c374dbd6013cd40dedbc25663d4837e381?s=96&d=mm&r=g\",\"caption\":\"Brad\"},\"sameAs\":[\"https:\/\/artisticimposter.com\",\"https:\/\/www.facebook.com\/kbwashburn\",\"https:\/\/www.instagram.com\/artisticimposterdesign\/\",\"https:\/\/www.linkedin.com\/in\/kbradleywashburn\/\",\"https:\/\/x.com\/bradwashburn\",\"https:\/\/www.youtube.com\/channel\/UC_SGOHbnI9Cy7byzKbQCFlA\"],\"url\":\"https:\/\/www.artisticimposter.com\/blog\/author\/kbwashburn\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Changing Web Page Items Using JavaScript | Artistic Imposter Design","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Changing Web Page Items Using JavaScript | Artistic Imposter Design","og_description":"I recently had a client who wanted a page with a SWF movie that could be changed to a different SWF by clicking on a button on the page. A while back, I did a project where the user could click a link and change the source of an image on the page using JavaScript, &hellip; Continue reading \"Changing Web Page Items Using JavaScript\"","og_url":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/","og_site_name":"Artistic Imposter Design","article_publisher":"https:\/\/www.facebook.com\/artisticimposter","article_author":"https:\/\/www.facebook.com\/kbwashburn","article_published_time":"2009-12-21T19:23:07+00:00","og_image":[{"width":275,"height":82,"url":"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/title.jpg","type":"image\/jpeg"}],"author":"Brad","twitter_card":"summary_large_image","twitter_creator":"@bradwashburn","twitter_site":"@bradwashburn","twitter_misc":{"Written by":"Brad","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#article","isPartOf":{"@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/"},"author":{"name":"Brad","@id":"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/2204a26e0617b620cb00fdb1d0111660"},"headline":"Changing Web Page Items Using JavaScript","datePublished":"2009-12-21T19:23:07+00:00","dateModified":"2009-12-21T19:23:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/"},"wordCount":473,"commentCount":0,"publisher":{"@id":"https:\/\/www.artisticimposter.com\/blog\/#organization"},"keywords":["JavaScript","Tips","Tutorials"],"articleSection":["JavaScript","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/","url":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/","name":"Changing Web Page Items Using JavaScript | Artistic Imposter Design","isPartOf":{"@id":"https:\/\/www.artisticimposter.com\/blog\/#website"},"datePublished":"2009-12-21T19:23:07+00:00","dateModified":"2009-12-21T19:23:07+00:00","breadcrumb":{"@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.artisticimposter.com\/blog\/changing-web-page-items-using-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.artisticimposter.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Changing Web Page Items Using JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.artisticimposter.com\/blog\/#website","url":"https:\/\/www.artisticimposter.com\/blog\/","name":"Artistic Imposter Design","description":"","publisher":{"@id":"https:\/\/www.artisticimposter.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.artisticimposter.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.artisticimposter.com\/blog\/#organization","name":"Artistic Imposter Design","url":"https:\/\/www.artisticimposter.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/cropped-logo.png","contentUrl":"https:\/\/www.artisticimposter.com\/blog\/wp-content\/uploads\/2020\/12\/cropped-logo.png","width":512,"height":512,"caption":"Artistic Imposter Design"},"image":{"@id":"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/artisticimposter","https:\/\/x.com\/bradwashburn","https:\/\/www.instagram.com\/artisticimposterdesign\/","https:\/\/www.linkedin.com\/company\/artistic-imposter-design","https:\/\/www.youtube.com\/channel\/UC_SGOHbnI9Cy7byzKbQCFlA"]},{"@type":"Person","@id":"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/2204a26e0617b620cb00fdb1d0111660","name":"Brad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.artisticimposter.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2bddfdea63dd2fdf76c199b2a705d0c374dbd6013cd40dedbc25663d4837e381?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2bddfdea63dd2fdf76c199b2a705d0c374dbd6013cd40dedbc25663d4837e381?s=96&d=mm&r=g","caption":"Brad"},"sameAs":["https:\/\/artisticimposter.com","https:\/\/www.facebook.com\/kbwashburn","https:\/\/www.instagram.com\/artisticimposterdesign\/","https:\/\/www.linkedin.com\/in\/kbradleywashburn\/","https:\/\/x.com\/bradwashburn","https:\/\/www.youtube.com\/channel\/UC_SGOHbnI9Cy7byzKbQCFlA"],"url":"https:\/\/www.artisticimposter.com\/blog\/author\/kbwashburn\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":0,"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.artisticimposter.com\/blog\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}