| | |
How to determine which button was pressed?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
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:
So, what results is something that looks like this:
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.
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
{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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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);
Please feel free to modify this code to match your needs. If you have any question regarding this code you can document.write('Me on my inbox'). lol! Have a good day...
html Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Some title</titles>
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- BEGIN HIDING /* All codes are tested before release, so you are well assured that all of my codes are hustle free... This example will determine which button is clicked. code is as follows: */ document.onclick = function( whichOne ) { whichOne = whichOne ? whichOne : window.event; thisButton = whichOne.target ? whichOne.target : whichOne.srcElement; if (( thisButton.name ) && ( thisButton.name == 'button1' )) { alert( '\n' + thisButton.title + ' was clicked!' ); } } // DONE HIDING --> </script>
html Syntax (Toggle Plain Text)
</head> <body> <p> <form> <input type="button" name="button1" title="Button One" value="Button 1" /> <input type="button" name="button1" title="Button Two" value="Button 2" /> <input type="button" name="button1" title="Button Three" value="Button 3" /> <input type="button" name="button1" title="Button Four" value="Button 4" /> </form> </p> </body> </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- how to create array of button in C# (C#)
- Computer doesn't boot (Troubleshooting Dead Machines)
- A multilingual coded Hello World! thread (Legacy and Other Languages)
- I need help covert my source code frm pic16c54a to pic16f84a (Assembly)
- Creating special classes (Java)
- Control button Click event (Visual Basic 4 / 5 / 6)
- Button Click Opens new file/program (VB.NET)
- PHP question regarding Forms (PHP)
- Setting the command buttons Forecolor (Visual Basic 4 / 5 / 6)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Validating email with javascrip problem
- Next Thread: Tooltips for feed description
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar cart checkbox child class codes column cookies createrange() css cursor decimal design disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox focus form forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent php player post problem progressbar prototype redirect regex runtime scale scroll search select session shopping size sql text textarea toggle validation w3c web website window windowofwords windowsxp wysiwyg \n





