Click here to Skip to main content
15,884,849 members
Home / Discussions / JavaScript
   

JavaScript

 
Question2nd Javascript Assignment Pin
Member 1119456830-Oct-14 18:02
Member 1119456830-Oct-14 18:02 
AnswerRe: 2nd Javascript Assignment Pin
Kornfeld Eliyahu Peter30-Oct-14 20:10
professionalKornfeld Eliyahu Peter30-Oct-14 20:10 
QuestionRe: 2nd Javascript Assignment Pin
ZurdoDev5-Nov-14 8:54
professionalZurdoDev5-Nov-14 8:54 
AnswerRe: 2nd Javascript Assignment Pin
Afzaal Ahmad Zeeshan8-Nov-14 1:41
professionalAfzaal Ahmad Zeeshan8-Nov-14 1:41 
QuestionJavascript assignment Pin
Member 1119456830-Oct-14 18:00
Member 1119456830-Oct-14 18:00 
AnswerRe: Javascript assignment Pin
Kornfeld Eliyahu Peter30-Oct-14 20:08
professionalKornfeld Eliyahu Peter30-Oct-14 20:08 
QuestionRe: Javascript assignment Pin
ZurdoDev5-Nov-14 8:55
professionalZurdoDev5-Nov-14 8:55 
QuestionHow to get array value Pin
Nishant.Chauhan8028-Oct-14 19:11
Nishant.Chauhan8028-Oct-14 19:11 
my controller code:-
XML
public class HomeController : Controller
    {

        erpEntities db = new erpEntities();

        public ActionResult Index()
        {


            string mysql = "select *  from modules where parentid=3";
            IEnumerable<Module> results = db.ExecuteStoreQuery<Module>(mysql);


            string itemString = "<table width='100px'><tr>";
            string itemString1 = "";

            Int32 ParentID = 0;
            Int32 ParentValue = 0;
            Int32 LevelID = 0;
            Int32 Mcounter = 0;
            Int32 LastValue = 0;
            foreach (var itemMain in results)
            {
                LevelID += 1;
                itemString1 += "<input type='hidden' id='LastValue" + LevelID + "' value=0>\n";

                itemString += "<td valign='top'><table width='200px'>";
                itemString += "<tr><td><b>" + itemMain.Title + "<b><td></tr>";
                mysql = "select Id,title  from t" + itemMain.ID;
                IEnumerable<ChildData> results1 = db.ExecuteStoreQuery<ChildData>(mysql);
                Mcounter = 0;

                foreach (var item in results1)
                {
                    Mcounter += 1;

                    string tt1 = item.ID.ToString();
                    string tt2 = item.ID.ToString();
                    string HidVar = Mcounter + "$" + LevelID;
                    itemString += "<tr><td>";
                    itemString += "<input type='hidden' id='Child$" + HidVar  + "' Value='" + item.ID + "'>";
                    itemString += "<input type='checkbox' id='chk$" + HidVar + "' value='' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + Mcounter + "," + LevelID + ");'>" + item.Title + "</a>";
                    //itemString += "<input type='checkbox' id='chk$" + ParentID + "$" + itemMain.ID + "$" + item.ID + "$" + LevelID + "' value=''><a href='#' onclick='javascript:clickme(\"" + HidVar + "\"," + tt1 + "," + tt2 + "," + LevelID + ");'>" + item.Title + "</a>";
                    itemString += "</td></tr>";
                }
                ParentID = itemMain.ID;
                itemString += "</td></table>";
            }



            itemString += "</tr></table>";

            //var ttp = db.t787.ToList();
            //itemString += "<table>";
            //foreach (var item in ttp)
            //{
            //    string tt1 = item.ID.ToString();
            //    string tt2 = item.ID.ToString();
            //    itemString += "<tr><td>";
            //    itemString += "<input type='hidden' id='modChild$786' value=1>";
            //    itemString += "<input type='checkbox' id='child$1$t7862" + item.ID + "'><a href='#' onclick='javascript:clickme(" + tt1 + "," + tt2 + ");'>" + item.Title + "</a>";
            //    itemString += "</td></tr>";
            //}
            //itemString += "</table>";

            ViewData["mystring"] = (itemString + itemString1);
            return View();
        }




My index.cshtml code:=


@{
ViewBag.Title = "Home Page";
// Response.Write(""" + "Hello"+""");
}

<script language="javascript" type="text/javascript">


var results = new Array();
function clickme(HidVar, txt, txt1,Mcounter, LevelID, ignore,rb)
{

//var input = document.createElement("input");
//input.setAttribute("type", "hidden");
//input.setAttribute("name", "name_you_want");
//input.setAttribute("value", "value_you_want");

var ChildValue = document.getElementById("Child$" + HidVar).value;
var chk = document.getElementById("chk$" + HidVar).checked;
//alert(chk);


// var chk1 = document.getElementById("chk$" + HidVar).checked = true;

if (LevelID > 1) {
for (index = 1; index < 4; ++index) {
if (Mcounter != index && document.getElementById("chk$" + HidVar).checked) {
document.getElementById("chk$" + index + "$" + LevelID).disabled = true;
}
if (document.getElementById("chk$" + HidVar).checked == false) {
document.getElementById("chk$" + index + "$" + LevelID).disabled = false;
}
}
}





document.getElementById("LastValue" + LevelID).value = ChildValue;

var ParentValue = 0;
if (LevelID > 1) {
ParentValue = document.getElementById("LastValue" + (LevelID - 1)).value;
}
else {

ParentValue = document.getElementById("LastValue" + (LevelID)).value;
}

// function checkbox(me, group) {




//load History
//alert("Level ID: " + LevelID);
//Remove Status - Unchecked all the value for a child Level
var OneToOne = 1;
for (index = 0; index < results.length; ++index) {
if (results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = false;
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = true;
}
}


//One to One Checking
var OneToNE = 0;
var ChildStatus = 0;
//Setting Status - checked all the value for a child Level
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ChildValue && results[index][2] >= (LevelID + 1)) {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;
if (OneToNE == 0) {
//document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).disabled = false;
}
ChildStatus = 1
}

}

//Checking if exist
var exist = 0;
for (index = 0; index < results.length; ++index) {
if (results[index][0] == ParentValue && results[index][1] == ChildValue && results[index][2] == LevelID && results[index][4] == Mcounter) {
exist = 1;
if (chk == false && ChildStatus == 0) {
removeByIndex(results, index);
}
else {
document.getElementById("chk$" + results[index][4] + "$" + results[index][2]).checked = true;

}
}
}

//IF not exist then storing in the array
if (exist == 0) {
results.push([ParentValue, ChildValue, LevelID, HidVar, Mcounter, "
"]);
}


document.getElementById("demo").innerHTML = results;

}

function removeByIndex(arr, index) {
arr.splice(index, 1);

}


</script>

<form name="addForm">
<input id="Button1" type="button" value="value" />


@Html.Raw(ViewData["mystring"]);
</form>

GeneralRe: How to get array value Pin
jkirkerx29-Oct-14 12:11
professionaljkirkerx29-Oct-14 12:11 
QuestionSelect2 Newline is created when item is selected Pin
Sander123432127-Oct-14 3:31
Sander123432127-Oct-14 3:31 
QuestionClick function not working the first time Pin
KokDavy27-Oct-14 1:43
KokDavy27-Oct-14 1:43 
Questionjavascript certification study pal Pin
Member 1117229022-Oct-14 3:13
Member 1117229022-Oct-14 3:13 
QuestionJQGrid and MIT license Pin
Sibeesh KV9-Oct-14 19:20
professionalSibeesh KV9-Oct-14 19:20 
AnswerRe: JQGrid and MIT license Pin
Richard Deeming9-Oct-14 22:52
mveRichard Deeming9-Oct-14 22:52 
GeneralRe: JQGrid and MIT license Pin
Sibeesh KV12-Oct-14 23:40
professionalSibeesh KV12-Oct-14 23:40 
AnswerRe: JQGrid and MIT license Pin
Sunasara Imdadhusen12-Oct-14 23:32
professionalSunasara Imdadhusen12-Oct-14 23:32 
GeneralRe: JQGrid and MIT license Pin
Sibeesh KV12-Oct-14 23:40
professionalSibeesh KV12-Oct-14 23:40 
Questiondropdown edit type selection to read mode for few records. Pin
parkway9-Oct-14 7:06
parkway9-Oct-14 7:06 
QuestionCross domain SOAP call (with XmlHttpRequest) to a webservice with windows authentication Pin
michielke8-Oct-14 22:12
michielke8-Oct-14 22:12 
Questionhow to display timer starting from 0 minutes and increment further Pin
Member 105573645-Oct-14 1:08
Member 105573645-Oct-14 1:08 
SuggestionRe: how to display timer starting from 0 minutes and increment further Pin
Kornfeld Eliyahu Peter5-Oct-14 1:15
professionalKornfeld Eliyahu Peter5-Oct-14 1:15 
QuestionJavascript and arrays Pin
Member 1111635128-Sep-14 16:32
Member 1111635128-Sep-14 16:32 
SuggestionRe: Javascript and arrays Pin
Kornfeld Eliyahu Peter28-Sep-14 20:58
professionalKornfeld Eliyahu Peter28-Sep-14 20:58 
QuestionJavascript and arrays Pin
Member 1111635128-Sep-14 16:30
Member 1111635128-Sep-14 16:30 
AnswerRe: Javascript and arrays Pin
Kornfeld Eliyahu Peter28-Sep-14 21:00
professionalKornfeld Eliyahu Peter28-Sep-14 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.