Results 1 to 13 of 13

Thread: Javascript Help Please - Show/Hide Divs based on TEXT input

  1. #1
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Javascript Help Please - Show/Hide Divs based on TEXT input

    Basically, i have a form which needs to show/hide and change names upon input of various selections from other forms within the page.

    so some are dropdowns and some are text variables.

    how do i do this?

    i get the logic involved, i.e.
    IF
    [fieldname]>0
    then show div
    Else
    dont show div
    End If

    How would i get this to work with javascript?

    say the fieldname is B4

    where would i put the javascript to read the form input in order to show the div?

    I've never really been big on client side varification, but im writing something currently that needs it and all the info i can find on the web relates to dropdowns, which i will be needing, but the text input is more important at the minute.

    Thanks In Advance

    Ste
    : RFNX Ste | : stegough | www.stegough.com

  2. #2
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    Code:
    function checkform ( form )
    {
      if (int(form.B4.value) > 0) {
        document.getElementById("B5div").style.visibility = 'visible';
        document.getElementById("B6div").style.visibility = 'visible';
    	alert("check");
        return false ;
      }
      if (form.B6.value > 0) {
        div.B7.style.visibility = 'visible'
        return false ;
      }
      // ** END **
      return true ;
    }
    what i have so far, but is not working

    it is being called by

    Code:
    <form onchange="return checkform(this);">
    any ideas?

    the alert is there to show me when it works, or if it gets that far, which it isnt, nor are the divs showing up
    : RFNX Ste | : stegough | www.stegough.com

  3. #3
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    Right, incase anyone wondered... it seems:

    you will not able to make it visible again cause 'getElementById("")' will fail to find out the 'id' of hidden control, therefore, display = "none" and display = "" must be used as opposed to visibility = "hidden" and visibility = "visible".

    its now working (somewhat... needs tweaking)
    : RFNX Ste | : stegough | www.stegough.com

  4. #4
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    it shouldn't make a difference whether the id is hidden or not as the code is still in the page to be manipulated.

    display will also hide the whole element (e.g closing up the space) but visibility only hides it (doesn't close up space on the page)

    Where in your code are you hiding the div too? I can only see you making it visible.

  5. #5
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    sorry, its being hidden at the div:

    Code:
    		<div class="clear" style="display:none;" id="B5div">
    			<span class="question">Is withdrawal based on fund value? Y/N</span>
    			<span class="answer">
    				<select name="B5">
    					<option value="y">Yes</option>
    					<option value="n">No</option>
    				</select>
    			</span>
    		</div>
    the problem i now seem to be having is that its reading the first part of the function:

    Code:
    function checkform ( form )
    {
      if (form.B4.value > 0) {
        document.getElementById("B5div").style.display = "";
        document.getElementById("B6div").style.display = "";
    	return;
      }{
        document.getElementById("B5div").style.display = "none";
        document.getElementById("B6div").style.display = "none";
    	return;
      }
    but it misses this next part totally, i think its because its being returned, but im not sure how to make it work through the checks, as this list will become quite long by the time i have programmed all the checks.

    Code:
      if (form.B6.value > 0) {
        document.getElementById("B7div").style.display = "";
    	return;
      }{
        document.getElementById("B7div").style.display = "none";
    	return;
     }
     return false;
    }
    without returning, the page does not update and i am left with too little form inputs.

    I realise that visibility sets the form with the space missing where the form will be and it gets filled in when visible, but that really doesnt concern me, it doesnt need the space there if the functionality is there.
    Last edited by mmh; 23-06-2008 at 01:05 PM. Reason: extra comments
    : RFNX Ste | : stegough | www.stegough.com

  6. #6
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    try changing the display ="" to display ="block"

    It should update without the returns, as mine does!

    I know it can be done other ways, but shouldn't there be an else after the first if statement?

    *** just checking this one out locally...***

  7. Received thanks from:

    mmh (23-06-2008)

  8. #7
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    haha, you beautiful tiggrrraaaiiii

    spot on

    i had missed out "else" totally.... (not using javascript much - if at all - i totally forgot to put else in the code, hence why it wasnt working properley... its working spot on now)

    thanks
    : RFNX Ste | : stegough | www.stegough.com

  9. #8
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    DOM manipulation can be a black art sometimes... only really been using it recently myself...

    a programming background does come in handy sometimes!

    My pleasure, happy to have been some help for once

    I can recommend the Javascript book from O'Reilly too (got a rhino on the front) it's straight forward and explains things properly.

  10. #9
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    my collegue has the o'reilly javascript book, but alas, it is not in the office today, nor is he!

    I do have a programming background, hence why i got the logic, but my primary problem is that i work mainly in asp with vb script as the languange, whereas javascript in my experience is more similar to C code, which i have only scratched the surface of
    : RFNX Ste | : stegough | www.stegough.com

  11. #10
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    Quote Originally Posted by mmh View Post
    my collegue has the o'reilly javascript book, but alas, it is not in the office today, nor is he!

    I do have a programming background, hence why i got the logic, but my primary problem is that i work mainly in asp with vb script as the languange, whereas javascript in my experience is more similar to C code, which i have only scratched the surface of
    Java is my background... but I tend to think of javascript functions as little classes.

    I failed my C module, so it can't be that! I suppose just having a very logical brain helps (I have no creativity... but give me a problem to solve and I can usually do it)

  12. #11
    mmh
    mmh is offline
    Full Stack Operator mmh's Avatar
    Join Date
    May 2005
    Location
    UK, Stourbridge
    Posts
    1,804
    Thanks
    148
    Thanked
    95 times in 56 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    hehe, i also have no creativity, which is why i get projects like the one i am on... im just currently doing the easy bit with the javascript, trying to sort out the inputs so as the client side shows the correct inputs to pass to the next page which took me a while to get my head around...

    the next page collects the data from the input form, sanitizes it, then copies a template excel file with some very complex formulas in it, inputs the passed data into selected fields in the excel file, opens said excel file and calculates all the formulae, then reads out selected pieces of information from the excel sheet and displays it on the page whilst deleting the excel file and (hopefully) eradicating any running instances of excel from the server to stop it getting bogged down.

    as you can imagine, having never dealt with connecting to excel files (fairly easy, just sql connection) and then having to find out how to run the excel file - a little more difficult as its not very well documented on the net for classic asp) and then pulling out the correct data....

    this whole project has given me a major headache, and im only about 50&#37; of the way through
    : RFNX Ste | : stegough | www.stegough.com

  13. #12
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    I've just been having some fun with Javascript to flash and back again...

    Dynamically changing the text in flash using javascript... havning not really scripted in javascript before then doing DOM manipulation similar to what you're doing above, to show / hide divs dependent on which flash file is showing...

    I'm quite proud of it actually!

  14. #13
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Javascript Help Please - Show/Hide Divs based on TEXT input

    Code:
    //jquery alt
    $(document).ready( function() {
      var my_val = 0;
      $('#my_form').change( function() {
        if ($('#my_form_input').val() [==][!=][...] my_val) {
          $('#my_div').hide();
          $('#my_other_div').show();
        }
      });
    });
    
    /*you could also re-fire code from external DOM sources too which could be handy in your case*/
    $(document).ready( function() {
      $('#my_ext_button').click( function() {
        $('#my_form').trigger('change');
      });
    )};
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with Nero
    By deathsith in forum Help! Quick Relief From Tech Headaches
    Replies: 2
    Last Post: 15-06-2007, 09:24 AM
  2. Open Office Writer - Header Numbering
    By ajbrun in forum Software
    Replies: 3
    Last Post: 07-05-2007, 12:23 PM
  3. Nero vision express saying:'Burn process failed'
    By johnnr892 in forum Help! Quick Relief From Tech Headaches
    Replies: 15
    Last Post: 11-12-2005, 11:43 PM
  4. JavaScript enabled input box
    By Kezzer in forum Software
    Replies: 3
    Last Post: 13-09-2005, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •