SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool I don't want "tblWeight" and "breakTag" to be displayed when page is first opened

    I have a function which works correctly but it has one problem. I have 2 radio buttons and if user clicks the radio button [1] then it will show the "tblWeight" and "breakTag" else do not display them. That is not the problem, the problem is thatwhen the user opens up the browser for the first time, I want the "tblWeight" and "breakTag" to not be displayed which should happen because of the "else" statement but it doesn't do it when the page is opened for the first time and thus it shows the "tblWeight" and "breakTag".

    Why is it display the "tblWeight" and "breakTag" when the page is first open? I did try turning my if statement around so that if ... then display none to "tblWeight" and "breakTag" else display it as block but this did not work.

    Below is my code:

    Code:
    	function getWeight() {
    			var weightChoice = document.getElementsByName("weightChoice");               
                var textWeight = document.getElementById("txtWeight");
                var tblWeight = document.getElementById("tblWeight");
                var breakTag = document.getElementsByClassName("breakTag");
                
                if(weightChoice[0].checked == true){
    	            tblWeight.style.display = "block";
    	            breakTag.style.display = "block";
    	            textWeight.value = 0;
    	            showData = false;
                }else{
    	            tblWeight.style.display = "none";
    	            breakTag.style.display = "none";
    	            textWeight.value = 0;
    
    		}
    
    	}
    Thank You

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you calling getWeight() either as a window.onload event handler or just above the closing </body> tag?

    If not, that is probably the cause of your problem.

    Where are you actually calling getWeight() ?

    Also, it's generally not a good idea to have variable names the same as id values.

    Also, also, you can hide the 2 elements by default in the css so that they do not appear on page load.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OMG can't believe I didn't think of setting display:none in css first. Thank You


Bookmarks

Posting Permissions

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