Announcement

Collapse
No announcement yet.

javascript parameter for function with pretext?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • javascript parameter for function with pretext?

    First off i was a little surprised this worked at all.
    Code:
    <script type="text/javascript">
    function test(myvar){
    	myvar();
    }
    function test_two(){
    	document.getElementById('mydiv').style.display = 'block';
    }
    </script>
    <input type="button" value="click" onClick="test(test_two);">
    <div id="mydiv" style="display:none;">helloworld</div>
    But now that i see that it does, i am trying to see if i can have "pre-text" before the parameter/var...
    Code:
    <script type="text/javascript">
    function test(myvar){
    	test_+myvar();
    }
    function test_two(){
    	document.getElementById('mydiv').style.display = 'block';
    }
    </script>
    <input type="button" value="click" onClick="test(two);">
    <div id="mydiv" style="display:none;">helloworld</div>
    Any thoughts anyone has would be appreciated.
    Thank you,
    Nick

  • #2
    Any thoughts
    HTML Code:
    <script>
    
    var funcs = {
      firstFunc: function(str) {
        alert(str);
      },
    
      secondFunc: function(str) {
        alert(str);
      },
    
      thirdFunc: function(str) {
        alert(str);
      }
    }
    
    var x = 'thirdFunc';
    funcs[x](x);
    
    </script>

    Comment

    Working...
    X