Home Ask Login Register

Developers Planet

Your answer is one click away!

user2089016 February 2016

javascript pararmeter pasing

I am not quite sure how to describe what I want....but here goes nothing.

I am trying to have multiple buttons that will show/hide a div (I have that part set up already). I would like the button to have two values (number and letter) that will then fill in a parameter for another button's onclick event (these need to change however depending on what button was originally clicked.

for example, I click button1 which has values a and 1. This then fills in the parameters for the onclick event for button 3. Or I can click button 2 which has b and 2 and this will fill in b and 2 for the parameters for button 3 (so button 3 on click parameters need to change)

I have been searching all day and can't seem to find anything. Can anyone offer any help or guidance?

<input type='button' value="1" id="1" name="1" onclick="toggle();" style="background-color:lightblue; height:75px; width:75px;-webkit-appearance: none; border-radius: 70px;
" />  

That button is what needs to have the two "values" of some sort Hamburger

That's the button that needs the values passed to the event.

var toggle = function() {
  var mydiv = document.getElementById('table1');
  if (mydiv.style.display === 'block' || mydiv.style.display === '')
    mydiv.style.display = 'none';
    mydiv.style.display = 'block'


J-DawG February 2016

It sounds to me like some having the function set some global variables would do the trick. Not entirely sure of what you're trying accomplish:

You can pass whatever parms you want to toggle:

<input type='button' value="1" id="1" name="1" onclick="toggle(1, a)" /> 

And then set them as global vars in in your JS:

var parm1, parm2;

var toggle = function(myChar, myInt) {
  parm1 = myChar;
  parm2 = myInt;

Post Status

Asked in February 2016
Viewed 2,844 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life