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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:58:56+00:00 2026-05-17T23:58:56+00:00

I have been working on this JavaScript file so that as someone types in

  • 0

I have been working on this JavaScript file so that as someone types in more text, they will see a different div showing them a piece of code (soon to be a Paypal button).

For some reason, I cannot get the divs to show up. I have used both onchange and onkeyup and neither seem to be helping. So, here is the code:

<br/>Word Count: <input type="text" id="c" name="c" value="311" size="5"
onkeyup="cnt(document.script.w,this)" onchange="showDiv()"/>
</form>

<div id="div1" style="display:none">
Price level 1!
</div>

<div id="div2" style="display:none">
Price level 2!
</div>

<div id="div3" style="display:none">
Price level 3!
</div>

<div id="div4" style="display:none">
Price level 4!
</div>

<div id="div5" style="display:none">
Price level 5!
</div>

<div id="div6" style="display:none">
Price level 6!
</div>

<div id="div7" style="display:none">
Price level 7!
</div>

Script

function showDiv() {
    var myNumValue = document.getElementById('c').value;
    var myNum = parseInt(myNumValue);
    var price1=0;
    var price2=100;
    var price3=200;
    var price4=300;
    var price5=400;
    var price6=500;
    var price7=600;
    
    if (myNum >= price1 && myNum <= price2) {
        document.getElementById('div1').style.display = 'block';
    }
    elseif(myNum >= price2 && myNum <= price3) {
        document.getElementById('div2').style.display = 'block';
    }
    elseif(myNum >= price3 && myNum <= price4) {
        document.getElementById('div3').style.display = 'block';
    }
    elseif(myNum >= price4 && myNum <= price5) {
        document.getElementById('div4').style.display = 'block';
    }
    elseif(myNum >= price5 && myNum <= price6) {
        document.getElementById('div5').style.display = 'block';
    }
    elseif(myNum >= price6 && myNum <= price7) {
        document.getElementById('div6').style.display = 'block';
    }
    else {
        document.getElementById('div7').style.display = 'block';
    }
}

So, any ideas on how to get this to work? I know I am probably just missing something simple, just need a couple of extra pairs of eyes.

  • 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-17T23:58:56+00:00Added an answer on May 17, 2026 at 11:58 pm

    The elseif => else if issue that amurra points out is your general problem, but I’d also like to suggest an alternative approach that uses an array of element IDs rather than ifs and else ifs. For instance:

    function showDiv() {
        var myNumValue = document.getElementById('c').value,
            myNum = Math.min(Math.floor(parseInt(myNumValue, 10) / 100), 6),
            myDiv = ["div1", "div2", "div3", "div4", "div5", "div6", "div7"][myNum];
    
        document.getElementById(myDiv).style.display = "block";
    }
    

    Much tidier, right? Live example at: http://jsfiddle.net/AndyE/FFeLC/1/ 🙂

    Note, however, that it’s not quite the same. In your example, if the value were 300 then div3 would be shown. In my example, div4 would be shown (which I think is more likely what you need). If you would prefer it how you have it in your code, you can subtract any amount between 0 and 0.1 from myNumValue after parsing it (and before dividing by 100) to get the same result you would expect from your code.

    Also, this is probably what you really want: http://jsfiddle.net/AndyE/FFeLC/2/.

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

Sidebar

Related Questions

I have been working on a project that dynamically creates a javascript file using
I have been working in a JavaScript file and my content has been working
I have been working on this for the greater part of the day and
I have been working on Flex for last couple of months and as this
I have this classic ASP site which has been working fine until we updated
I have been working with a string[] array in C# that gets returned from
I have been working on some legacy C++ code that uses variable length structures
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
We have been working with CVS for years, and frequently find it useful to

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.