grayrest wrote:
> The Keyword search (http://www.mozillanews.org/index.php3?article=55 for 
> those not in the know) is great, but I would really like to be able to 
> send the info via POST due to 
> http://cgi.gatech.edu/cgi-bin/directory/lookup not accepting GET 
> variables. I did see the followup to that mozillanews article saying 
> that POST works for him, but I think that's due to the server running a 
> recent CGI.pm that can take both, but it does not work at the gatech 
> address (http://cgi.gatech.edu/cgi-bin/directory/lookup/whois?name=%s 
> fails). Is there any way to do this?
> 
> grayrest
> 

Finally got it. For those that care:

function doForm(url,valary){
     if(document.getElementById && document.createElement){
        var form = document.createElement("form");
        document.getElementsByTagName("body")[0].appendChild(form);
        form.setAttribute("action", url);
        form.setAttribute("method", "POST");
        for(var i=0; i < valary.length; i++){
            var temp=document.createElement("input");
            form.appendChild(temp);
            temp.setAttribute("type", "hidden");
            temp.setAttribute("name", valary[i][0]);
            temp.value = valary[i][1];
        }
     }
     form.submit();
}
function doParse(url){
     var pairs = url.substring(url.indexOf('?')+1).split("&");
     url = url.substring(0,url.indexOf('?'));
     var valary;
     for (var i=0;i<pairs.length;i++){
        var pos = pairs[i].indexOf('=');
        if (pos >= 0){
            var name = pairs[i].substring(0,pos);
            var value = pairs[i].substring(pos+1);
            if(valary)
                valary[valary.length]=[name, value];
            else
                valary = [[name, value]];
        }
     }
     return doForm(url,valary);
}
doParse("http://cgi.gatech.edu/cgi-bin/directory/lookup/whois?name=%s";);

As a bookmarklet:

javascript: function doForm(url,valary){ if(document.getElementById && 
document.createElement){ var form = document.createElement("form"); 
document.getElementsByTagName("body")[0].appendChild(form); 
form.setAttribute("action", url); form.setAttribute("method", "POST"); 
for(var i=0; i < valary.length; i++){ var 
temp=document.createElement("input"); form.appendChild(temp); 
temp.setAttribute("type", "hidden"); temp.setAttribute("name", 
valary[i][0]); temp.value = valary[i][1]; } } form.submit(); } function 
doParse(url){ var pairs = url.substring(url.indexOf('?')+1).split("&"); 
url = url.substring(0,url.indexOf('?')); var valary; for (var 
i=0;i<pairs.length;i++){ var pos = pairs[i].indexOf('='); if (pos >= 0){ 
var name = pairs[i].substring(0,pos); var value = 
pairs[i].substring(pos+1); if(valary) valary[valary.length]=[name, 
value]; else valary = [[name, value]]; } } return doForm(url,valary); } 
doParse("http://cgi.gatech.edu/cgi-bin/directory/lookup/whois?name=%s";);

to use, change the end URL to be whatever you like, you can place as 
many variables on it as you want, the script should handle it.

grayrest


Reply via email to