Created
October 12, 2009 02:23
-
-
Save nickel/208071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function newElement(object_name, method, resource, controller, div, prompt_text){ | |
var name = prompt(prompt_text); | |
if(name) { | |
field = object_name + "[name]"; | |
$.post("/" + controller, {'element[name]' : name}, function(response) { | |
var html = "<select name='" + object_name + "[" + method + "]' id='" + object_name + "_" + method + "'><option value=''/>"; | |
for(var i=0;i<response.length;i++){ | |
html += "<option value='" + response[i][resource].id + "'>" + response[i][resource].name + "</option>" | |
if(response[i][resource].name == name) { | |
var id = response[i][resource].id | |
} | |
} | |
$("#" + div).html(html); | |
$("#" + object_name + "_" + method).children("[value=" + id + "]").attr("selected", "selected") | |
}, "json"); | |
} else { | |
window.alert("Debe introducir un nombre"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment