I want to this, a button that changed to disable when click, while there is something sent to the database.

I worked with ajax, I can do this with a submit button, but when I i put the form tag, not work any more.

Can you give me some available solution for this ?

8 Years
Discussion Span
Last Post by fatihpiristine

> I worked with ajax, I can do this with a submit button, but when I i
> put the form tag, not work any more.

It worked because Ajax doesn't depend on a FORM element for shipping data to and fro; it uses the XMLHttpRequest object for this purpose.

Also, doesn't work is a pretty useless description, we need more description or a sample snippet which showcases the problem at hand.


dont know how much you know about javascript but this will do the thing that you want.

this one adds butons into body onclick event and changes its label to delete and
delete buton delete any other button randomly (doesnt remove itself)
this was an interview question

object model used to support ie4+

replace document.body.removeChild(btns[tmp]); and add there what you want and it will work.

var q = q ? q : new Object();
/* create document element */
q.CreateElement = function(tagName) {
    return document.createElement(tagName);
/* set element attribute */
q.SetAttribute = function(element, attName, attValue) {
    return element.setAttribute(attName, attValue);
/* append element to given parent */
q.AppendChild = function(parent, newChild) {
    return parent.appendChild(newChild);
/* set element class name */
q.ClassName = function(element, className) {
    return element.className = className;
/* fetch source element of the event */
q.GetTarget = function(ev) {
    var target;
    if (!ev) var ev = window.event;
    if (ev.target) target = ev.target;
    else if (ev.srcElement) target = ev.srcElement;
    if (target.nodeType == 3)
        target = target.parentNode;
    return target;
/* button click event */
q.buttonClick = function(event) {
	as we cannot pass parameter with the event (possible in IE Browsers),
	checking the value of source element.
    if (q.GetTarget(event).value.indexOf("Add") == 0) {
        var newBtn = q.CreateElement("input");
        q.SetAttribute(newBtn, "value", "Delete");
        q.SetAttribute(newBtn, "type", "button"); /* set type of the input */
		/* attach event to new button */
        if (newBtn.addEventListener) { /* if FF */
            newBtn.addEventListener('click', q.buttonClick, event);
        } else { /* if IE */
            newBtn.attachEvent('onclick', q.buttonClick);
        q.ClassName(newBtn, "q");
        q.AppendChild(document.body, newBtn);
    else {
        var btns = document.getElementsByTagName("INPUT");
        var tmp; /* temporary value */
        while (tmp = Math.floor(Math.random() * 10)) {
            if (tmp < btns.length) /* boosting */ {
					check if the button has no values as "Add" and
					not the sender itself, remove it
                if (btns[tmp].value.indexOf("Add") != 0 && btns[tmp] != q.GetTarget(event)) {
                    break; /* end the loop */
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.