Hi all,
I am a newbie. I have finally succeded in adding elements like lable, text box & buttons in a <div> elemet dynamically in script. But, the onclick event of te button doesnot work.
I tried different ways to access the GetDirection method, but couldnot get it, Their is no error message. Also can I retrive text box value in getDirections by document.getElement....Code:function createDrivePanel() { var odiv = document.getElementById("directDIV"); var fromLbl=document.createElement("label"); fromLbl.setAttribute("for", "drFrom"); fromLbl.innerHTML="Drive From: "; // var toLbl=document.createElement("<label for="drTo">Drive To: </label>"); var dynamicForm=document.createElement("form"); dynamicForm.setAttribute("id", "dynamicForm"); dynamicForm.setAttribute("runat", "server"); var fromTxt=document.createElement("input"); fromTxt.setAttribute("type", "text"); fromTxt.setAttribute("id", "fromTxt"); fromTxt.setAttribute("value", ""); var toTxt=document.createElement("input"); toTxt.setAttribute("type", "text"); toTxt.setAttribute("id", "toTxt"); toTxt.setAttribute("value", ""); var getDirectionsBtn=document.createElement("input"); getDirectionsBtn.setAttribute("type", "button"); getDirectionsBtn.setAttribute("id", "getDirectionsBtn"); getDirectionsBtn.setAttribute("value", "Get Directions"); // getDirectionsBtn.setAttribute("onClick", "GetDirections"); // getDirectionsBtn.setAttribute("onClick", "GetDirections()"); getDirectionsBtn.setAttribute("onclick", "GetDirections(" + fromTxt.value + ", " + toTxt.value +")"); // getDirectionsBtn.attachEvent("onclick", "GetDirections(" + fromTxt.value + ", " + toTxt.value +")"); alert("all elements Inits"); dynamicForm.appendChild(fromLbl); dynamicForm.appendChild(fromTxt); dynamicForm.appendChild(document.createElement("<br>")); // frm.appendChild(toLbl); dynamicForm.appendChild(toTxt); dynamicForm.appendChild(document.createElement("<br>")); dynamicForm.appendChild(getDirectionsBtn); odiv.insertBefore(dynamicForm, lbl); // document.getElementById('directDIV').innerHTML = odiv; } function GetDirections(from, to) { // ResultsPanel.Controls.Add("Drive From " + from + "Drive To " + to); // alert("Drive From " + document.getElementById('fromTxt') + "Drive To " + document.getElementById('toTxt')); alert("Drive From " + from + "Drive To " + to); }
I am in very bad shape & need to fix it asap.
I believe, I am not doing anything incorrect, technically. If such a thing is not possible what could be the other alternative. I am using IE 6.
Any help is appreciated. Hope you guys will be able to help me out.
Thanks
Trupti



Reply With Quote

Bookmarks