0

I have a trouble while using a javascript function in a while loop.My function executes only once.Given below is the code.

I called a function inside a while loop.That called function calls an another function. I want to execute the first function till the end of while loop,But it executes only once.

Thanks in advance.

while(p<=10)
    {
        k=0;
        l=0;
        var contExp= mycontents[p].split("#");
        var divExp= mydivs[p].split(",");
        var schtime=contExp[k];
            alert(contExp[k]);
        document.getElementById('gymlocationz').value=contExp[k+1];
        document.getElementById('fitness').value=contExp[k+2];
        document.getElementById('duration').value="1 hour";
        alert(p);
        return select_visibility(divExp[l],divExp[l+1],divExp[l+2],contExp[k],mycontents[p]);
        //l=l+3;
        p++;
    }

function select_visibility(str,str1,timeid,time,cont) 
{
  var contExp= cont.split("#");
  var e = document.getElementById(str);
  var esub=document.getElementById(str+'sub');
  var fulldv=str+'sub';
  var result = timeid.match(/([0-9]+)/g);
    $('#'+str1).addClass('act');
    $('#'+str+'sub').addClass('act');
    document.getElementById(timeid).value=time;
    document.getElementById('fitness'+result).value=document.getElementById('fitness').value;
    document.getElementById('gymlocat'+result).value=document.getElementById('gymlocationz').value;
    document.getElementById('selectdrpact'+result).value=contExp[3];
    document.getElementById('repeat'+result).value=contExp[4];
    var s=document.getElementById('fitness'+result).value;
$("#"+str).css(
{
   "background-color":"#95c5ec",
   "border":"1px solid #ddd",
   "text-decoration":"none",
   "padding":"10px 0px",
   "margin-left":"30px"
});
    $("#"+fulldv).css(
    {
       "background-color":"#95c5ec",
       "border":"1px solid #ddd",
       "text-decoration":"none",
       "padding":"10px 0px",
       "margin-left":"41px"
    });
    e.style.display = 'block';
    esub.style.display = 'block'; 
    selecteditems();
    //return true;
}

function selecteditems()
{
    var i=1;
    var fld = "";
    document.getElementById("showselecteditems").innerHTML="";
    while(i<=53)
    {
    fldOne = document.getElementById('datepicker_value').value;
    fld = document.getElementById('timedrpact'+i).value;
    fidpartnum = document.getElementById('selectdrpact'+i).value;
    fidrepeat = document.getElementById('repeat'+i).value;

    fit=document.getElementById('fitness'+i).value;
    if(fit=="Select")
    {
        fit="Fitness Not Selected";
        }
    if(fld!="")
    {
            //var par='ddwnx'+i;

            //alert(fit+","+i+","+fld);
            var ele = document.createElement("div");
        ele.setAttribute("id","showselecteditems"+i);
        ele.setAttribute("class","inner");
        ele.innerHTML=fit+"&nbsp;,&nbsp;"+fldOne+"&nbsp;,&nbsp;"+fld+"&nbsp;,&nbsp;"+fidpartnum+"&nbsp;Paticipants, &nbsp;"+fidrepeat+"&nbsp;Repeat";
    }
    i++;
}

}

1 Answer 1

3

You are using a return statement inside your while loop. The return statement will cause the function to stop running and return a value to whatever code called the function. The problem is this line:

return select_visibility(divExp[l],divExp[l+1],divExp[l+2],contExp[k],
    mycontents[p]);

Change it to this:

select_visibility(divExp[l],divExp[l+1],divExp[l+2],contExp[k],mycontents[p]);

That will call the select_visibility() function without causing the function containing the loop to terminate.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.