Announcement Announcement Module
Collapse
No announcement yet.
javascript input if then display Page Title Module
Move Remove Collapse
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript input if then display

    #1
    Hi guys! me again.
    Have a question about javascript (still a newbie).
    I need to make a div to display (block or none) depending on the input.

    Example: if the input = 1 then display the next div to be none, but if the input = 2 then display the next div to be block.

    Any help is again greatly appreciated!

  • #2
    Anybody?

    Comment


    • #3
      Just apply an event listener to the input field.

      Comment


      • #4
        Kindly, could you explain how this is done?

        Comment


        • #5
          Are you using any additional libraries, like Jquery?

          Comment


          • #6
            yes I am

            Comment


            • #7
              Are you referring to something as simple as this?

              http://sanpitch.com/junk/gd_forum_example.html

              Comment


              • #8
                ooooooooooo I think that may work. I'll have to play around with it. Thanks <b>!

                Comment


                • #9
                  hmmmm actually I will need that type of function but on an input text box.

                  My predicament is that the way my client's web page is built, it does some kind of crazy calculations based on a spreadsheet that has been converted/processed into an html page
                  So this function needs to be something like type a "1" or a "2" (because that actually affects the calculations) a "1" would not display the next div and a "2" would.

                  If it were my choice, I'd just rebuild the whole page, but unfortunately I need to make the least amount of changes as possible so that it doesn't affect the calculations......

                  Comment


                  • #10
                    Are you talking about something like this?
                    Don't have an example of what it does on hand, but it should be self explanatory. I'm not sure how many options you need, but you can add more case statements if you need more.

                    HTML elements

                    <input type='text' class='tb'/>
                    <div class='dv'>asldkjlkj</div>

                    SCRIPT



                    $(".tb").keyup( function(){
                    tbd = $(".tb").val();

                    switch(tbd){
                    case "1":
                    $(".dv").css('display', "block");
                    break;
                    case "2":
                    $(".dv").css('display', "block");
                    break;
                    default:
                    $(".dv").css('display', "none");
                    }

                    });

                    Comment


                    • #11
                      Is the data from this spreadsheet actually displayed on the page in the form of, say, a table or a list? You mentioned it being part of the HTML, so I'm assuming that it's displayed. Or am I wrong about that? Is it just a bunch of hidden numbers against which a calculation has to be made that depends on an input variable from the user?

                      If it's a relatively simply calculation, it might be appropriate to handle it with JavaScript, but when you start talking about spreadsheets it's sort of sounding like something where a server-side scripting language and a database might be more appropriate. It doesn't make a lot of sense to me to embed a whole bunch of numerical data into a JavaScript to pass of the calculations to the users' machines when it could all be done on the server before serving the page, unless, of course, I've misunderstood or the Ajax responsiveness of this is especially important for some reason.

                      There are just too many questions here to give you a good answer, and unless I've misunderstood, it's sounding like some custom scripting.

                      Comment


                      • #12
                        Thanks Obsidian86,
                        Looks like it should work, but I have no luck maybe I'm doing something wrong...

                        Comment


                        • #13
                          @ <b>
                          the way this is built, or i should say "built", was a spreadsheet was submitted to one of these 'we'll instantly convert your spreadsheet into a working html page' websites. It works, but the file looks like a bunch of code vomited all over the place... so all of the calculations are through javascript inside that one page.

                          Comment


                          • #14
                            Obsidian86,
                            I've tried your code and played around with the jquery and everything I could think of, but still can't get it to work...

                            I need to get this done soon, but have run out of luck. If anyone can help I'd greatly appreciated, and I appreciate everyone who has helped out so far.
                            I'm almost to the point where I'd hand it off to someone else to take care of so that I don't have to worry about it.

                            Comment


                            • #15
                              Interesting. It works for me, so there's not much I can do without seeing the code, because there's only like 1 billion things that could go wrong or be effecting it.

                              Comment

                              Google search Google search Module
                              Collapse
                              Latest Topics Latest Topics Module
                              Collapse
                              All Creative World Network All Creative World Network Module
                              Collapse
                               
                              home | site map | advertising/sponsorships | about us | careers | contact us | help courses | browse jobs | freelancers | events | forums | content | member benefits | reprints & permissions about | terms of use | privacy policy | Copyright © 2013 Mediabistro Inc. Mediabistro Inc. call (212) 389-2000 or email us
                              Working...
                              X