Go Back   Graphic Design Forum > Graphic Design > Web Design

Web Design Web Design type posts here

Reply
 
Thread Tools Display Modes
Old 02-20-2013, 02:08 PM   #1
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
javascript input if then display

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!
kamehameha is offline   Reply With Quote
Old 02-21-2013, 07:48 PM   #2
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
Anybody?
kamehameha is offline   Reply With Quote
Old 02-21-2013, 07:55 PM   #3
Obsidian86
ಠ_ಠ
 
Obsidian86's Avatar
 
Join Date: Jul 2009
Location: Houston Area- Texas
Posts: 2,433
Just apply an event listener to the input field.
__________________
"I used to wonder what friendship could be, Until you all shared its magic with me." - Jesus Christ
Obsidian86 is offline   Reply With Quote
Old 02-22-2013, 01:16 PM   #4
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
Kindly, could you explain how this is done?
kamehameha is offline   Reply With Quote
Old 02-22-2013, 06:07 PM   #5
Obsidian86
ಠ_ಠ
 
Obsidian86's Avatar
 
Join Date: Jul 2009
Location: Houston Area- Texas
Posts: 2,433
Are you using any additional libraries, like Jquery?
__________________
"I used to wonder what friendship could be, Until you all shared its magic with me." - Jesus Christ
Obsidian86 is offline   Reply With Quote
Old 02-26-2013, 12:05 PM   #6
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
yes I am
kamehameha is offline   Reply With Quote
Old 02-26-2013, 03:20 PM   #7
<b>
Living the dream
 
<b>'s Avatar
 
Join Date: Jan 2011
Location: Somewhat south of Idaho
Posts: 2,945
Are you referring to something as simple as this?

http://sanpitch.com/junk/gd_forum_example.html
__________________
— I feel more like I do now than I did before I got here.
<b> is offline   Reply With Quote
Old 02-26-2013, 05:38 PM   #8
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
ooooooooooo I think that may work. I'll have to play around with it. Thanks <b>!
kamehameha is offline   Reply With Quote
Old 02-26-2013, 08:37 PM   #9
kamehameha
Member
 
kamehameha's Avatar
 
Join Date: Mar 2011
Posts: 71
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......
kamehameha is offline   Reply With Quote
Old 02-26-2013, 09:26 PM   #10
Obsidian86
ಠ_ಠ
 
Obsidian86's Avatar
 
Join Date: Jul 2009
Location: Houston Area- Texas
Posts: 2,433
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");
}

});
__________________
"I used to wonder what friendship could be, Until you all shared its magic with me." - Jesus Christ
Obsidian86 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:27 AM.




GRAPHICS.COM NEWSLETTER
The weekly Graphics.com newsletter is a great way to stay up to date on what's new on the site and in the world of graphics. Subscribe »

JOB LISTINGS
Featured Listings
Art Director
Hanley Wood
Washington, DC
Designer
Environmental Defense Fund
New York, NY
Presentation Designer
Refinery29
New York, NY
Lead Artist (m/f)
GameDuell
Berlin, Germany

See all other great design jobs on our Job Board

Post a risk-free
job listing for $279


WebMediaBrands
Mediabistro | All Creative World | Inside Network
Jobs | Education | Research | Events | News
Advertise | Terms of Use | Privacy Policy
Copyright 2011 WebMediaBrands Inc. All rights reserved.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.