Search code examples
jquery-pluginsimpromptu

Jquery Impromptu 4


I'm having a hard time with impromptu(jquery plugin) where I keep getting an undefined value. Here is an example:

<img id=dispatch title='Click to dispatch(COMING SOON)' onclick=Dispatch(0) src='../images/icons/truck_green.png' width=16 height=16/>
<img id=dispatch title='Click to dispatch(COMING SOON)' onclick=Dispatch(1) src='../images/icons/truck_green.png' width=16 height=16/>
<img id=dispatch title='Click to dispatch(COMING SOON)' onclick=Dispatch(2) src='../images/icons/truck_green.png' width=16 height=16/>
<img id=dispatch title='Click to dispatch(COMING SOON)' onclick=Dispatch(3) src='../images/icons/truck_green.png' width=16 height=16/>

function Dispatch(id){
           var driver = 'Enter the drivers name:<br><input type="text" id="alertName" name=myname value="" />';

           $.prompt(driver,{   
                    submit: myfunc,
                    buttons: { Ok:true }                         
            });
        }  

function myfunc(e,v,m,f){                
            var an = m.children('#alertName');

            if(f.alertName == ""){
                    an.css("border","solid #ff0000 1px");
                    return false;
            }
            return true;
        }

Eventually I want to take the id and the name typed and do some AJAX. But I cant get the css change. I alerted f.alertName and got undefined and I don't know why. Thank for your help.


Solution

  • I believe you want f.myName. Learn to step through with debugger and examine objects. The answer quickly became obvious.

    http://jsfiddle.net/ULeQz/1/

    var driver = 'Enter the drivers name:<br><input type="text" id="alertName" name="myname" value="" />';
    
    $.prompt(driver, {
        submit: myfunc,
        buttons: {
            Ok: true
        }
    });
    
    function myfunc(e, v, m, f) {
        debugger;
        var an = m.children('#alertName');
    
        if (f.myname == "") {
            an.css("border", "solid #ff0000 1px");
            return false;
        }
        return true;
    }​