Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    JavaScript Array And split().....

    First_Name=David`Last_Name=Grover`Home_Phone=111-111-1111`Work_Phone=111-111-1111`Cell_Phone=111-111-1111`Street=720 Kennedy Rd`Apt=1007`City=Scarborough`Province=ON`Postal_Code=M1K 2B7`Intersection=Keedy Rd X Eglon`Equipment=Total Gym 1000, 10X24 Foot Room`Session_Week=2`Sessions_Purchased=0`Days_Time_Preferred=Mon:12:00 am,1:00 am`Sessions_Left=0`Height=5.8`Weight=190`Goals=`Injury=None`Inj_Date=1900-01-01`Precaution=None`Doc_Clearence=None`Special_Order=None`Other_Concern=None`Exer_Program=None`Curren t_Exer_Resist=None`Supplementary=None`Howlong=None`Flexibility=1/1`Musk_Power=2/2`Rel_Mus_Stren=3/3`Cardio=4/4`Wall_Sit=5/5`Co_Ordi=Average`Musk_Endur=7/7`Abs_Mus_Stren=8/8`Body_Compo=9/9`Push_Ups=10/10`Sit_Ups=6/6`Core=12/12`Body_Fat=6`Weight=190`Notes=None`Assess_Dt=2009-01-26


    The above is the value of var str value, returned by Database. So I use below code to split and put the values back to the form. but it does not work.
    The alert displays right value( Last_Name=Grover ), but if I try to open the comments of for loop OR s = nameVal[0].split("="); the function never called at all.... I am not bothered about switch function fo rnow. Can anybody help me. I am new to JavaScript. I try to reply asap for any query. thank you.


    var nameVal = new Array();
    nameVal = str.split("`");
    var s = new Array();
    //for( int i=0; i<nameVal.length; i++) {
    // s = nameVal[0].spilt("=");
    alert( nameVal[1] + " "+nameVal.length);

    /*switch (s[0]) {
    case "Province" : //document.forms.Province.selectedIndex = s[1];
    break;
    case "Session_Week" : //document.forms.Session_Week.selectedIndex = s[1];
    break;
    case "Sessions_Purchased" : //document.forms.Sessions_Purchased.selectedIndex = s[1];
    break;
    case "Days_Time_Preferred" : //document.forms.Province.selectedIndex = s[1];
    break;
    case "Height" : //document.forms.Height.selectedIndex = s[1];
    break;
    case "Weight" : //document.forms.Weight.selectedIndex = s[1];
    break;
    case "Howlong" : //document.forms.Howlong.selectedIndex = s[1];
    break;
    case "Co_Ordi" : //document.forms.Co_Ordi.selectedIndex = s[1];
    break;
    case "Sessions_Left" : //document.forms.Province.selectedIndex = s[1];
    break;
    case "Body_Fat" : //document.forms.Body_Fat.selectedIndex = s[1];
    break;
    default: document.getElementsByName(s[0])[0].value=s[1];
    }*/
    //}

  • #2
    New Coder
    Join Date
    Feb 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The whole code is in the following function, called when the fprm is loaded with onload event.

    function init(str) {
    ....
    ....
    .... all the code.
    ....
    ....
    ....

    }

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi everyone,
    replacing int in the for loop with var solved the problem. also the split works and the function is being called.

    now trying for the switch case problem. if anyone has the idea of if case value can be string.... early response is appreciated. thank you. let u know if I am able to solve it.

    bye

  • #4
    New Coder
    Join Date
    Feb 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Switch("asdf") {

    case "asdf" :

    break;

    }

    the switch case also works fine


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •