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

  • Home
  • SEARCH
  • 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 8952585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:54:26+00:00 2026-06-15T13:54:26+00:00

I have an HTML page which contains: a <select> dropdown with 3 options with

  • 0

I have an HTML page which contains:

  • a <select> dropdown with 3 options with an onchange event to a JS function
  • a DIV holder with a script element inside:

Here’s the code:

<select onChange="getData(this.value);">
    <option value="-">Limba/Language</option>
    <option value="ro">Romana</option>
    <option value="en">Engleza</option>
</select>
<div id="output">
    <script id="widget" type="text/javascript" src="js1.js"></script>
</div>

And here’s the JS function:

<script type="text/javascript">
function getData(title)
{
    switch(title)
    {
        case "ro":
            var s = document.createElement("script");
                s.type = "text/javascript";
                s.src = "js1.js";
                s.innerHTML = null;
                s.id = "widget";
                document.getElementById("output").innerHTML = s;
        break;
        case "en":
            var s = document.createElement("script");
                s.type = "text/javascript";
                s.src = "js2.js";
                s.innerHTML = null;
                s.id = "widget";
                document.getElementById("output").innerHTML = s;
        break;
        default:
        void(0);
    }
}
</script>

When I select option 2 or 3 I get this output in my browser: [object HTMLScriptElement]

What I want to do is switch the src property of the script tag based on the value selected in the dropdown element.
I want to do this client-side and preferably without any external libraries…

  • 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-06-15T13:54:27+00:00Added an answer on June 15, 2026 at 1:54 pm

    The other solution is great 🙂
    …but if you still want to create elements via JavaScript you should use appendChild instead of innerHTML…

    Here is what your JavaScript should be 🙂

    <script type="text/javascript">
    function getData(title)
    {
        switch(title)
        {
            case "ro":
                var s = document.createElement("script");
                    s.type = "text/javascript";
                    s.src = "js1.js";
                    s.innerHTML = null;
                    s.id = "widget";
                    document.getElementById("output").innerHTML = "";
                    document.getElementById("output").appendChild(s);
            break;
            case "en":
                var s = document.createElement("script");
                    s.type = "text/javascript";
                    s.src = "js2.js";
                    s.innerHTML = null;
                    s.id = "widget";
                    document.getElementById("output").innerHTML = "";
                    document.getElementById("output").appendChild(s);
            break;
            default:
            void(0);
        }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following HTML page, I have a div, which contains two spans (
I have an html page called search.html which contains sliders, they work perfectly in
I have this html page which is very simple, it contains a text box
I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
I'm pretty new to PHP and have a String which contains an HTML page.
I have a form on my page which contains two select dropdowns. The first
If I have a page which contains an iframe: <iframe src=blank.html id=frame></iframe> and I
I have a HTML page which contains users data and the data is stored
I have an HTML page which contains an href tag. On clicking href link,
I have a web page which contains a select box. When I open a

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.