Search code examples
javascripthtmldetection

How to detect data from multiple buttons in HTML/Javascript


I am quite new at developing html files and i came across 1 problem. Lets say i have 6 pictures, that work as buttons(they open popups etc). So my question is... How can i pass data from what img was pressed and display it in a label?

img button code looks like this:

<td width="33%"><a onClick='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");'><img src="img/klumpanje.gif" width="202" height="77"></a></td>

label is in a separate file of popup, looks like this:

<div class='container'>
    <label  for='message'>Izbira:</label><br/>
    <span id='contactus_message_errorloc' class='error'></span>
    <input name="message" type="text" id="message" value="knof1" size="50" readonly="readonly" />
</div>

Ty for the answers.


Solution

  • I created a new function that calls the popup and sent argument by that function

    <td width="33%"><a id="kl" onClick='test("1");'> <img src="img/klumpanje.gif" width="202" height="77"></a></td>
    

    function:

    function test(tmp){
        var elem = document.getElementById('message');  
    
        if( tmp == "1")
        {
            elem.value="Klumpanje";
        }...
        javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup","kl");
      }
    

    Finnaly got it working. TY all for the answers, much appreciated :).