DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   submit once button (http://www.daniweb.com/forums/thread167959.html)

runrunforest Jan 12th, 2009 10:26 pm
submit once button
 
Hi,

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 ?

sillyboy Jan 12th, 2009 11:06 pm
Re: submit once button
 
<form>
  <input type="submit" disabled="disabled">
</form>

~s.o.s~ Jan 13th, 2009 12:08 pm
Re: submit once button
 
> 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.

fatihpiristine Jan 13th, 2009 7:52 pm
Re: submit once button
 
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)) {
                    document.body.removeChild(btns[tmp]);
                    break; /* end the loop */
                }
            }
        }
    }
};


All times are GMT -4. The time now is 5:36 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC