Jump to content

Button name passed through


unemployment

Recommended Posts

Any idea how to accomplish this?

 

requestform.onsubmit = function ()
{
/* So what to do here, thats the question

- I want to get the data / NAME of a button that has been pressed, if such function exists.
- Then I need to use AJAX to send the form data to some file that probably doesnt exist yet.
- Give the PHP a response, and echo the response to replace the buttons

*/

return false;
}

Link to comment
https://forums.phpfreaks.com/topic/234273-button-name-passed-through/
Share on other sites

The event.explicitOriginalTarget object contains the object which triggered the original event. So as an example for the first step of what you want to achieve:

 

<script type="text/javascript">
window.onload = function() {
    document.requestform.onsubmit = function(event) {
        alert('Name: ' + event.explicitOriginalTarget.name);
        alert('Value: ' + event.explicitOriginalTarget.value);

        return false;
    }
}
</script>

<form name="requestform">
    <input type="submit" name="ButtonName1" value="Button Value 1" />
    <input type="submit" name="ButtonName2" value="Button Value 2" />
</form>

I have posted the full code.  I alert only works for the last input1 in my list of inputs. 

 

Any idea how to make this result happen?

 

if (link)
{
	link.onclick = function()
	{
		var uid = link.href.split('=');
		uid = uid[1];

		ajax.get('/assets/ajax/partner_review.php?uid=' + uid, function(responce)
		{
			var info = eval('(' + responce + ')');
			var i;

			lightbox.show(info[0], function(body)
			{

				for (i = 0; i < info[1].length; ++i) 
				{
					var row 		= document.createElement('div');
					var div1 		= document.createElement('div');
					var a			= document.createElement('a');
					var img 		= document.createElement('img');
					var span 		= document.createElement('span');
					var div2		= document.createElement('div');
					var div3		= document.createElement('div');
					var input1		= document.createElement('input');
					var input2		= document.createElement('input');
					var requestform	= document.createElement('form');

					input1.type = 'submit';
					input2.type = 'submit';

					input1.value = 'Accept';
					input2.value = 'Deny';

					input1.name = 'acceptrequest[' + info[1][i].uid + ']';
					input2.name = 'denyrequest[' + info[1][i].uid + ']';

					requestform.name = 'requestform';
					requestform.method = 'post';
					requestform.action = 'http://mysite.com/home.php';

					a.href = 'http://mysite.com/u/' + info[1][i].username;
					a.setAttribute('target', '_blank');

					addClass(row, 'lb_row');

					img.src = info[1][i].avatar;
					img.alt = info[1][i].displayName;

					row.appendChild(div1);

					a.appendChild(img);
					div1.appendChild(a);
					addClass(div1, 'lb_div');
					addClass(div1, 'tdfirst_review');
					addClass(img, 'avatar extrasmall vmiddle');

					span.appendChild(document.createTextNode(info[1][i].displayName)) 
					a.appendChild(span);
					addClass(span, 'lb_span');

					div2.appendChild(input1);
					row.appendChild(div2);
					addClass(div2, 'lb_div_button');
					addClass(div2, 'lb_align');

					div3.appendChild(input2);
					row.appendChild(div3);
					addClass(div3, 'lb_div_button');
					addClass(div3, 'lb_align');
					addClass(div3, 'right');

					requestform.appendChild(row);
					body.appendChild(requestform);

					requestform.onsubmit = function ()
					{
						/* So what to do here, thats the question

						- You want to get the data of the button that has been pressed, if such function exists.
						- Then use AJAX to send the form data to some file that probably doesnt exist yet.
						- Give the PHP a responce, and echot he response to replace the buttons

						*/
						input1[i].onclick = function ()
						{
							alert(input1.name);
						}

						return false;
					}
				}
			});
		});

		return false;
	}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.