Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    returnvalues as parameters for HTML-tags

    Hello.

    I'm working on a progressbar for my blog, and I've looking for a method to easily controll the text it shows, since it's always one of 8 states.

    For this i wanted to create a javascript and a switch which would give the right percentage of filling for the progressbar. Unfortunatly it doesn't fill the progressbar as wanted.

    Code:
    <script type="text/javascript">
    var t = 6;
    
    function percent()
    	{
    	switch (t)
    		{
    		case 1:
    			return 12.5;
    			break;
    		case 2:
    			return 25;
    			break;
    		case 3:
    			return 37.5;
    			break;
    		case 4:
    			return 50;
    			break;
    		case 5:
    			return 62.5;
    			break;
    		case 6:
    			return 75;
    			break;
    		case 7:
    			return 87.5;
    			break;
    		case 8:	
    			return 100;
    			break;
    		case 0:
    			return 0;
    			break;
    		default:
    			return 0;
    		}
    	}
    </script>
    
    <div class="”goal”" style="”width:195px;height:15px;background:#0d0d1c;border:solid" 1px="">
    <div class="”progress”" style="height:15px;background:#1e90ff;color:white;width:javascript:percent()%"><b>0</b>
    </div></div>
    Could someone show me where I am going wrong with this please?
    And if it matters: My blog is a *.blogspot.com
    Thanks

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Code:
     <body>
    
    
    <progress class='progress'></progress>	
    
    
    <script>
    function percent(t){
    	return document.getElementsByClassName("progress")[0].value=(
                { 1: 12.5, 2:25, 3:37.5, 4:50, 5:62.5, 6:75, 7:87.5, 8:100}[t]||0)/100;
    }
    </script>
    
    
    Set Progress:  
      <input value='1' type='button' onclick="percent(this.value)" />	
      <input value='3' type='button' onclick="percent(this.value)" />	
      <input value='4' type='button' onclick="percent(this.value)" />	
      <input value='6' type='button' onclick="percent(this.value)" />	
      <input value='8' type='button' onclick="percent(this.value)" />	
    
    
    </body>
    tested ff6, ch13
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This isn't what I wanted, but I figured out, I can't use the returnvalue of a javascript-function as an input for an HTML-Tag.

    Can be closed.


  •  

    Posting Permissions

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