1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Issue

Discussion in 'JavaScript' started by Spider-Man, May 11, 2008.

  1. #1
    Hey guys, freshly back from my recent ban :)() and have an issue with javascript.

    Basically I have a piece of code like this:
    
     <select name='PAYMENTMETHOD' size="1"
     onChange="javascript:HideCCDetails(this)" >
    Code (markup):
    Then a div, with a list box, and 4 fields. The list box, when option (with the value 10005 is selected, the fields should be displayed, otherwise they should be hidden.

    <script language=javascript type='text/javascript'>
     function hideDiv()
     {
     if (document.getElementById)
     { // DOM3 = IE5, NS6
     document.getElementById('CCDetails').style.visibility = 'hidden';
     }
     else
     {
     if (document.layers)
     { // Netscape 4
     document.CCDetails.visibility = 'hidden';
     }
     else
     { // IE 4
     document.all.CCDetails.style.visibility = 'hidden';
     }
     }
     }
     
     function showDiv() {
     if (document.getElementById) { // DOM3 = IE5, NS6
     document.getElementById('CCDetails').style.visibility = 'visible';
     }
     else {
     if (document.layers) { // Netscape 4
     document.CCDetails.visibility = 'visible';
     }
     else { // IE 4
     document.all.CCDetails.style.visibility = 'visible';
     }
     }
     }
     
     function HideCCDetails(selectObj)
     {
     if (selectObj.options[selectObj.selectedIndex].value == "10005")
     {
     showDiv();
     }
     else
     {
     hideDiv();
     }
     }
     </script>
    
    Code (markup):
    How can I edit the second part of the script so that the <div> for CC details is hidden all the time, and it only shown when the object with the value 10005 is selected. It works at the moment, but not when the page first loads, I need the fields to be hidden when the page loads.

    Any ideas?

    Thanks:D
     
    Spider-Man, May 11, 2008 IP
  2. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #2
    And this was placed in the HTML part of the forum and not the JavaScript part because?
     
    twistedspikes, May 11, 2008 IP
  3. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To test your patience? I joke, I joke - I've requested it to be moved. My apologies:)
     
    Spider-Man, May 11, 2008 IP
  4. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #4
    No worries :D, just thought you'd get a better response over there, thats why I asked.
     
    twistedspikes, May 11, 2008 IP
  5. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nobody? :(
     
    Spider-Man, May 11, 2008 IP
  6. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You just want to make it so the DIV is hidden by default? I think you were right in placing this in the HTML section at first since this is about HTML/CSS.

    You can just simply do <div style="visibility:hidden;"> as your div (though I'm not sure if I'd recommend using the "visibility" setting since I think it's different with each browsers.. I tend to use display:none; for hiding them and display:block; for reshowing)
     
    zerxer, May 11, 2008 IP
    Spider-Man likes this.
  7. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks Zerxer, I'll just load that in and upload it and see if it works.

    Cheers,
    Spidey
     
    Spider-Man, May 11, 2008 IP
  8. Spider-Man

    Spider-Man Banned

    Messages:
    2,684
    Likes Received:
    211
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Zerxer, unfortunately my laptop only has IE7 and Firefox2 installed - the code you gave, <div style="visibility:hidden;"> works perfectly in both. I will need to install other browsers on my desktop PC to check compatibility, but so far - this one does it:D Unfortunately the page where this is placed is mid way through the checkout so I can't check it using virtual browsers :( Anyway, I'll keep you updated.

    Cheers,
    Spidey
     
    Spider-Man, May 11, 2008 IP