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 6132811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:08:57+00:00 2026-05-23T17:08:57+00:00

I am new to javascript. I have a function I modifed that when a

  • 0

I am new to javascript.

I have a function I modifed that when a user selects “Yes” from a pull down menu it creates 3 text boxes in a div area.

Here is my form pull down code:

    <select name="dosage" id="dosage" onchange="function dosage(sel)">
            <option value="No">No</option>
            <option value="Yes">Yes</option> 

    </select>
<div id="dosagearea"></div>

This is the javascript I modified which originally created a message box to the user when they selected something.

    function dosage(sel)
{
   if(sel.options.selectedIndex == 0)
   {

      return false;
   }


    else if(sel.options.selectedIndex == 'Yes')
       {
          x=document.createElement('input');
                    x.setAttribute('rows',1);
                    x.setAttribute('cols',20);
                    x.name='dosage_emitted';
                    document.getElementById('dosagearea').appendChild(x);

            x=document.createElement('input');
                    x.setAttribute('rows',1);
                    x.setAttribute('cols',20);
                    x.name='dosage_absorbed';
                    document.getElementById('dosagearea').appendChild(x)


            x=document.createElement('input');
                    x.setAttribute('rows',1);
                    x.setAttribute('cols',20);
                    x.name='dosage_period';
                    document.getElementById('dosagearea').appendChild(x)
       }
    } 

I checked with firebug and no JS errors being returned, I think my function is not being called the right way.

Thanks

  • 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-23T17:08:57+00:00Added an answer on May 23, 2026 at 5:08 pm

    The value of the onchange property is basically the name of a function or some JavaScript. If you want to call your function with the select element as a parameter, you need to do

    <select name="dosage" id="dosage" onchange="dosage(this)">
    

    Note that this isn’t the recommended way to do things as it couples your HTML with your JS. Instead, try adding the event directly in JS, like so

    window.onload = function() {
        document.getElementById("dosage").onchange = dosage;
        function dosasage(event) {
            var sel = event.currentTarget;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that dynamically creates a new button through JavaScript that when
I have a scenario where a javascript function creates a new span element in
I have used Javascript onlaod like this: function check() { var pic = new
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
I have an HTML form that builds a drop-down from json data that is
I have a view that contains a javascript function that i need to init/call
I have a javascript function (class) that takes a function reference as one paremter.
In one HTML page I have a JavaScript function checkUpdates() that hits the server.
I'm quite new to javascript but have undertaken a task to get better aquainted
I have opened a new window with JavaScript: var newwin = window.open('','preview','width=600,height=500'); Now I

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.