I'm trying to determine which button was pressed when I'm unsure of how many buttons there actually are...
The smarty template that I'm using creates the input buttons based on a query that happens in the associated php script. I don't know how many input fields will actually be generated, otherwise, I'd just add an event listener for all of them. But, I can't seem to get the yui code to "figure out" which button was pressed. When the user presses one of the buttons, then a form should display.
This is the smarty code:
{foreach from=$value.sample_query key=key item=value2 name="samp"}
{foreach from=$value2 item=value3}
{$value3} <input type="button" id="sample{$key}" name="sample[{$key}]" value="" />
{/foreach}
{/foreach}
So, what results is something that looks like this:
<input type="button" id="sample0" name="sample[0]" value="" />
<input type="button" id="sample1" name="sample[1]" value="" />
<input type="button" id="sample2" name="sample[2]" value="" />
<input type="button" id="sample3" name="sample[3]" value="" />
The YUI code is below, which will be used to popup a form depending upon which button was pressed. Wherever there's a reference to "sample0" in the code below, *that's* what needs to change to the id of the button that was actually pressed.
YAHOO.namespace("forms.container");
function init() {
// Define various event handlers for Dialog
var handleSubmit = function() {
this.submit();
};
var handleCancel = function() {
this.cancel();
};
var handleSuccess = function(o) {
var response = o.responseText;
response = response.split("<!")[0];
document.getElementById("resp").innerHTML = response;
};
var handleFailure = function(o) {
alert("Submission failed: " + o.status);
};
// Instantiate the Dialog
YAHOO.forms.container.sample0 = new YAHOO.widget.Dialog("sample0",
{ width : "330px",
fixedcenter : true,
zindex: 100,
visible : false,
constraintoviewport : false,
buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
{ text:"Cancel", handler:handleCancel } ]
});
// Wire up the success and failure handlers
YAHOO.forms.container.sample0.callback = { success: handleSuccess,
failure: handleFailure };
// Render the Dialog
YAHOO.forms.container.sample0.render();
YAHOO.util.Event.addListener("showsample0", "click", YAHOO.forms.container.sample0.show, YAHOO.forms.container.sample0, true);
YAHOO.util.Event.addListener("hidesample0", "click", YAHOO.forms.container.sample0.hide, YAHOO.forms.container.sample0, true);
}
YAHOO.util.Event.onDOMReady(init);