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.
Page 3 of 3 FirstFirst 123
Results 31 to 42 of 42
  1. #31
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    I used attrName and attrValue as a representative value to show the syntax, and it must be replaced by the attribute and value that you want to add/set.
    E.g.
    Code:
    SaveCheck[S].src = 'Pic1.png';
    or
    Code:
    SaveCheck[S].setAttribute('src' , 'Pic1.png');
    adds src="Pic1.png" to the tag
    Code:
    SaveCheck[S].id= 'Output';
    or
    Code:
    SaveCheck[S].setAttribute('id' , 'Output');
    adds id="Output"
    Code:
    SaveCheck[S].className = 'blueborder';
    or
    Code:
    SaveCheck[S].setAttribute('class' , 'blueborder');
    adds class="blueborder"
    (also one of the exceptions as it is either className or class depending n which way you want to add it)

    to make a checkebox checked you can either use:
    Code:
    SaveCheck[S].checked = true;
    (also an exception as it is set as a boolean)
    or
    Code:
    SaveCheck[S].setAttribute['checked', 'checked'];

  2. #32
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    OK, I now understand the logic.

    BTW, I used the .checked = true; method because the other setAttribute method didn't add anything.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  3. #33
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    Quote Originally Posted by tpeck View Post
    the other setAttribute method didn't add anything.
    Well! It is understandable:
    I mistakenly wrote it with brackets instead of parenthesises.
    Corrected, it is:
    Code:
    SaveCheck[S].setAttribute('checked', 'checked');
    Last edited by Lerura; 08-13-2014 at 03:55 PM.

  4. #34
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    I am trying to use your methods to rewrite these document.writes:

    Code:
    <script type="text/javascript">
    var mf = "";
    var mf = readCookie('mfcookie');
    if(mf == 1){
    document.write("<input type=\"radio\" onclick=\"createCookie(\'mfcookie\',value,9999);\" id=\"male\" name=\"mf\" value=1 checked \/>");
    }
    else {
    document.write("<input type=\"radio\" onclick=\"createCookie(\'mfcookie\',value,9999);\" id=\"male\" name=\"mf\" value=1 \/>");
    }
    document.write("<label for=\"male\" class=\"pointer\">male<\/label><br>");
    if(mf == 2){
    document.write("<input type=\"radio\" onclick=\"createCookie(\'mfcookie\',value,9999);\" id=\"female\" name=\"mf\" value=2 checked \/>");
    }
    else {
    document.write("<input type=\"radio\" onclick=\"createCookie(\'mfcookie\',value,9999);\" id=\"female\" name=\"mf\" value=2 \/>");
    }
    document.write("<label for=\"female\" class=\"pointer\">female<\/label><br>");
    </script>
    I'm not far off (I think), but the checked and labels parts still confound me:

    Code:
    <script>
    var MfImage = [], MfTitAlt = [], MfTxt = [];
    
    MfImage['0']='images/male.png';     MfTitAlt['0'] = 'male voice';	MfTxt['0']=' male';
    MfImage['1']='images/female.png';   MfTitAlt['1'] = 'female voice';	MfTxt['1']=' female';
    </script>
    
    <div id="gender">
    </div>
    <script>
    var Genderlist=document.getElementById('gender');
    var SaveCheck=[];
    var GenderPic=[];
    var GenderTxt=[];
    var gender = readCookie('mfcookie');
    	for (S=0;S<2;S++){
    	SaveCheck[S] = document.createElement('input');
    	SaveCheck[S].setAttribute('type','radio');
    	SaveCheck[S].setAttribute('onclick',"createCookie('mfcookie'),value,9999);");	
    	SaveCheck[S].setAttribute('value',"" + (S+1) + "");
    	SaveCheck[S].checked = true;
    	GenderPic[S] = document.createElement('img');
    	GenderPic[S].src = MfImage[S];
    	GenderPic[S].setAttribute('title',MfTitAlt[S]);
    	GenderPic[S].setAttribute('alt',MfTitAlt[S]);
    	GenderPic[S].setAttribute('style', 'height:16px;width:16px;' );
    	GenderTxt[S]=document.createElement('label');
    	GenderTxt[S].textContent=MfTxt[S];	
    	br=document.createElement('br');
    	Genderlist.appendChild(SaveCheck[S]);
    	Genderlist.appendChild(GenderPic[S]);
    	Genderlist.appendChild(GenderTxt[S]);	
    	Genderlist.appendChild(br);
    }
    </script>
    The way I have set it up in the cookie is for mfcookie to be 1 for male and 2 for female.

    Am I hopelessly off track or within a whisker? Do I need an if/else for the checked part?
    Last edited by tpeck; 08-14-2014 at 02:46 AM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  5. #35
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    You are pretty close actually.
    but you have forgotten some attributes:
    name for the radiobuttons (without it they do not act together)
    for and class for the labels
    and added an extra right parentehis to the onclick

    Personally I would rename the keys for the array to '1' for male and '2' for female:
    Code:
    MfImage['1']='images/male.png';     MfTitAlt['1'] = 'male voice';    MfTxt['1']=' male';
    MfImage['2']='images/female.png';   MfTitAlt['2'] = 'female voice';    MfTxt['2']=' female';
    and change the loop initiation to:
    Code:
    for (S=1;S<3;S++){
    to avoid confusion and to simplify assignment and comparison within the loop.
    when S = 1 then we are then both dealing with loop run number 1 , and any assignment/comparison will be directly related to S,
    instead og having to add +1 in some places and skip it in other places, and end up with adding it the wrong places.

    Then to check of the right radiobutton we can compare gender and S directly.
    Code:
    Savecheck[S].checked = (gender == S);
    and set the value by:
    Code:
    SaveCheck[S].setAttribute('value',S)
    with some lines added or edited we then get:
    Code:
    <script>
    var MfImage = [], MfTitAlt = [], MfTxt = [];
    
    MfImage['1']='images/male.png';     MfTitAlt['1'] = 'male voice';    MfTxt['1']=' male';
    MfImage['2']='images/female.png';   MfTitAlt['2'] = 'female voice';    MfTxt['2']=' female';
    </script>
    
    <div id="gender">
    </div>
    <script>
    var Genderlist=document.getElementById('gender');
    var SaveCheck=[];
    var GenderPic=[];
    var GenderTxt=[];
    var gender = readCookie('mfcookie');
        for (S=1;S<3;S++){
        SaveCheck[S] = document.createElement('input');
        SaveCheck[S].setAttribute('type','radio');
        SaveCheck[S].setAttribute('name','mf');
        SaveCheck[S].setAttribute('onclick',"createCookie('mfcookie',value,9999);");    
        SaveCheck[S].setAttribute('value',S);
        SaveCheck[S].checked = (gender == S);
        GenderPic[S] = document.createElement('img');
        GenderPic[S].src = MfImage[S];
        GenderPic[S].setAttribute('title',MfTitAlt[S]);
        GenderPic[S].setAttribute('alt',MfTitAlt[S]);
        GenderPic[S].setAttribute('style', 'height:16px;width:16px;' );
        GenderTxt[S]=document.createElement('label');
        GenderTxt[S].setAttribute('for', MfTxt[S] );
        GenderTxt[S].setAttribute('class', 'pointer' );
        GenderTxt[S].textContent=MfTxt[S];    
        br=document.createElement('br');
        Genderlist.appendChild(SaveCheck[S]);
        Genderlist.appendChild(GenderPic[S]);
        Genderlist.appendChild(GenderTxt[S]);    
        Genderlist.appendChild(br);
    }
    </script>

  6. #36
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Of course, the radio button needs the name, how stupid of me.

    It works very well. You are a great teacher! I'm just a little concerned about the time you are spending. I hope others will get as much from this as me.\

    For anyone who might be following this, I forgot this line too (for the label to function: when clicked checks the radio button):

    Code:
        SaveCheck[S].setAttribute('id',MfTxt[S]);
    Last edited by tpeck; 08-14-2014 at 07:41 AM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  7. #37
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    I am currently developing a kind of library for DOM creation, so this thread helps we remember the opportunities/needs. So I am actually learning from it myself too.
    That I at the same time can sense that you also are trying to work out the solution yourself, and not just rely on me giving you C&P solutions, is a huge motivator for continuing.
    Each reply take on average 10 minutes, so it is not stealing my day.

  8. #38
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    That's good to know! I am almost at the end. I have managed to replace 4 largish blocks of ugly document.writes with this method, and it's certainly an improvement.

    This should be the last question. It's a similar block to an earlier one you have shown me, but it works slightly differently:

    Code:
    <script type="text/javascript">
    var TypeImage=[], TypeTitAlt=[], BG=[], MfImage=[], MfTitAlt=[];
    
    TypeImage['R']='images/R.png';    TypeTitAlt['R']='random session';
    TypeImage['1']='images/P1.png';   TypeTitAlt['1']='preset session#1';
    TypeImage['2']='images/P2.png';   TypeTitAlt['2']='preset session#2';
    TypeImage['3']='images/P3.png';   TypeTitAlt['3']='preset session#3';
    TypeImage['4']='images/P4.png';   TypeTitAlt['4']='preset session#4';
    TypeImage['5']='images/P5.png';   TypeTitAlt['5']='preset session#5';
    
    BG['1']=' (silent) '
    BG['2']=' (ocean waves) '
    BG['3']=' (forest) '
    BG['4']=' (meditative) '
    BG['5']=' (orchestral) '
    BG['6']=' (piano) ';
    
    MfImage['1']='images/male.png';     MfTitAlt['1']='male voice';
    MfImage['2']='images/female.png';   MfTitAlt['2']='female voice';
    
    ...
    }
    </script>
    <div id="sessions">
    </div>
    <script type="text/javascript">
    var Sessionlist=document.getElementById('sessions');
    var SaveCheck=[];
    var PlayImage=[];
    var Time=[];  
    var GenderPic=[];
    var Background=[];
    var TypePic=[];
    var store=readCookie('sessioncookie');
    	if(! store){ // no recorded sessions (null)
    	document.write("<i>NO RECORDED SESSIONS</i>");
    	}
    	[COLOR="#FF0000"]else {
    	var saved=readCookie('mycookie');
    		if(saved){ // if saved sessions exist
    		var MySessions=saved.match(/.{1,36}/g); // ???
    		}
    	var Sessions=store.match(/.{1,36}/g);
    	Sessions.sort(sortsegments)
    	for (S=0;S<Sessions.length;S++){
    	type=Sessions[S].substr(0,1);
    	gender=Sessions[S].substr(1,1);
    	bg=Sessions[S].substr(2,1);
    	time=Sessions[S].substr(3,13);
    	SaveCheck[S]=document.createElement('input');
    	SaveCheck[S].setAttribute('id',"box" + (S+1) + "");
    	SaveCheck[S].setAttribute('type','checkbox');
    	SaveCheck[S].setAttribute('onclick',"saveasMypreset(value, this);");
    	SaveCheck[S].setAttribute('value',"" + S + "");
    	SaveCheck[S].checked=(MySessions==S);	
    	PlayImage[S]=document.createElement('img');
    	PlayImage[S].src='images/bmp_play.png';	
    	PlayImage[S].setAttribute('class','pointer');
    	PlayImage[S].setAttribute('title','replay');
    	PlayImage[S].setAttribute('alt','replay');	
    	PlayImage[S].setAttribute('style','height:16px;width:16px;');
    	PlayImage[S].setAttribute('onclick',"replaySession('" + type+S + "');");
    	Time[S]=document.createElement('span');
    	Time[S].textContent=getAMPMstring(new Date(parseInt(time))); 
    	GenderPic[S]=document.createElement('img');
    	GenderPic[S].src=MfImage[gender];
    	GenderPic[S].setAttribute('title',MfTitAlt[gender]);
    	GenderPic[S].setAttribute('alt',MfTitAlt[gender]);
    	GenderPic[S].setAttribute('style','height:16px;width:16px;');
    	Background[S]=document.createElement('span');
    	Background[S].textContent=BG[bg];
    	TypePic[S]=document.createElement('img');
    	TypePic[S].src=TypeImage[type];
    	TypePic[S].setAttribute('title',TypeTitAlt[type]);
    	TypePic[S].setAttribute('alt',TypeTitAlt[type]);
    	TypePic[S].setAttribute('style','height:16px;width:16px;');  
    	br=document.createElement('br');
    	Sessionlist.appendChild(SaveCheck[S]);
    	Sessionlist.appendChild(PlayImage[S]);  
    	Sessionlist.appendChild(Time[S]);
    	Sessionlist.appendChild(GenderPic[S]);
    	Sessionlist.appendChild(Background[S]);
    	Sessionlist.appendChild(TypePic[S]);
    	Sessionlist.appendChild(br);
    	}
    }
    </script>
    The part which I am trying to get to function correctly is the blue line.

    The checkboxes should only get checked on page load if the (36 char) session appears somewhere in the cookie "mycookie". So the var "saved" needs to be searched for a match. I thought I might be doing that with the green line above, but it is not helping check any checkboxes. I don't have a good enough handle on what that green line is actually doing.

    Another thing, as you can see I am still using a document.write - which I can live with - but I don't suppose you are likely to do that. Is it acceptable?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  9. #39
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    Using the document.write makes the line appear in the document at the location where the script is run/called, and since the script is run after #sessions
    Code:
    <div id="sessions">
    </div>
     script runs here
    the result will be
    Code:
    <div id="sessions">
    </div>
    <i>NO RECORDED SESSIONS</i>
    and we can't run the script inside #sessions as the div then would not be closed at the time the script is run and therefore not exists yet. Hence we cannot append anything to it.

    Technically document.write adds its content after all content currently existing on page.


    - - - - - - - - - - - - - - - - - - - - -

    The green line splits saved into segments of length 36 and stores each segment as an entry in Mysessions.
    Technically by searching for a match -> storing the match as an MySessions[0] ->
    continuing the search for another match from the characters just after the last match -> storing this match as MySessions[1]
    and so forth until it reaches the end of the string.

    - - - - - - - - - - - - - - - - - - - - -

    The test for if sessioncookie exist can be made before the loop.
    But they testing of sessioncookie vs mycookie must be done for each entry.
    Either by another loop, that set a true or false for each segment, to use in the exiting loop.
    or within the existing loop.
    Code:
    var store = readCookie('sessioncookie');
    if(! store)){
      var SCE = false; // (sessioncookie exists) = false
      noCookie = document.createElement('span');
      noCookie.textContent = 'NO RECORDED SESSIONS';
      noCookie.setAttribute('style','font-style:italic;')
      Sessionlist.appendChild(noCookie);
    } else {
      SCE = true;
    }
    saved = readCookie('mycookie');
      var Sessions = saved.match(/.{1,36}/g);
      Sessions.sort(sortsegments);
    for (S=0;S<Sessions.length;S++){
      type=Sessions[S].substr(0,1);
      gender=Sessions[S].substr(1,1);
      bg=Sessions[S].substr(2,1);
      time=Sessions[S].substr(3,13);
      SaveCheck[S]=document.createElement('input');
      SaveCheck[S].setAttribute('id',"box" + (S+1) + "");
      SaveCheck[S].setAttribute('type','checkbox');
      SaveCheck[S].setAttribute('onclick',"saveasMypreset(value, this);");
      SaveCheck[S].setAttribute('value',"" + S + "");
       SaveCheck[S].checked=(SCE && store.indexOf(Sessions[S]!=-1);
      PlayImage[S]=document.createElement('img');
      PlayImage[S].src='images/bmp_play.png';    
      PlayImage[S].setAttribute('class','pointer');
      PlayImage[S].setAttribute('title','replay');
      PlayImage[S].setAttribute('alt','replay');    
      PlayImage[S].setAttribute('style','height:16px;width:16px;');
      PlayImage[S].setAttribute('onclick',"replaySession('" + type+S + "');");
      Time[S]=document.createElement('span');
      Time[S].textContent=getAMPMstring(new Date(parseInt(time))); 
      GenderPic[S]=document.createElement('img');
      GenderPic[S].src=MfImage[gender];
      GenderPic[S].setAttribute('title',MfTitAlt[gender]);
      GenderPic[S].setAttribute('alt',MfTitAlt[gender]);
      GenderPic[S].setAttribute('style','height:16px;width:16px;');
      Background[S]=document.createElement('span');
      Background[S].textContent=BG[bg];
      TypePic[S]=document.createElement('img');
      TypePic[S].src=TypeImage[type];
      TypePic[S].setAttribute('title',TypeTitAlt[type]);
      TypePic[S].setAttribute('alt',TypeTitAlt[type]);
      TypePic[S].setAttribute('style','height:16px;width:16px;');
      br=document.createElement('br');
      Sessionlist.appendChild(SaveCheck[S]);
      Sessionlist.appendChild(PlayImage[S]);  
      Sessionlist.appendChild(Time[S]);
      Sessionlist.appendChild(GenderPic[S]);
      Sessionlist.appendChild(Background[S]);
      Sessionlist.appendChild(TypePic[S]);
      Sessionlist.appendChild(br);
    }
    Please note that this lists all sessions stored in mycookie and checks it if the session is stored in sessioncookie too.
    but any session only stored in sessioncookie will not be listed.
    and any session only stored in mycookie will be listed but not checked

    So this solution assumes that all sessions (saved and recorded) is stored within mycookie,
    and that sessioncookie only contains recorded sessions.

    If it is opposite: that sessioncookie contains all sessions and mycookie only contains saved sessions.
    Then we have to reverse the script

    If both sessioncookie and mycookie may contain sessions that are not contained within the other cookie,
    and all sessions both recorded and saved must be listed.
    Then we have to make a merged array containing all sessions and remove eventual duplicates from it, and then continue from there.

    And I hope that you are aware that the result of
    Code:
      PlayImage[S].setAttribute('onclick',"replaySession('" + type+S + "');");
    will be that if the type of session in the sorted list of sessions in order is e.g. 4,R,1,1,5 then the onclicks will be respectively:
    replaySession('40'); , replaySession('R1'); , replaySession('12'); , replaySession('13'); and replaySession('54');

    I have a feeling that you only want to pass the sessions position within the sorted list of sessions.
    in which case the line must be:
    Code:
      PlayImage[S].setAttribute('onclick',"replaySession('" + S + "');");
    Last edited by Lerura; 08-15-2014 at 09:45 PM.

  10. Users who have thanked Lerura for this post:

    tpeck (08-16-2014)

  11. #40
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    That's so helpful. I believe I have got it:

    Code:
    <div id="sessions">
    </div>
    <script type="text/javascript">
    var Sessionlist=document.getElementById('sessions');
    var SaveCheck=[];
    var PlayImage=[];
    var Time=[];  
    var GenderPic=[];
    var Background=[];
    var TypePic=[];
    var store = readCookie('sessioncookie');
        if(! store){ // no stored sessions (null)
        noCookie=document.createElement('span');
        noCookie.textContent='NO RECORDED SESSIONS';
        noCookie.setAttribute('style','font-style:italic;')
        Sessionlist.appendChild(noCookie);
        }
    var Sessions=store.match(/.{1,36}/g);
    Sessions.sort(sortsegments);
        for (S=0;S<Sessions.length;S++){
        type=Sessions[S].substr(0,1);
        gender=Sessions[S].substr(1,1);
        bg=Sessions[S].substr(2,1);
        time=Sessions[S].substr(3,13);
        SaveCheck[S]=document.createElement('input');
        SaveCheck[S].setAttribute('id',"box" + (S+1) + "");
        SaveCheck[S].setAttribute('type','checkbox');
        SaveCheck[S].setAttribute('onclick',"saveasMypreset(value, this);");
        SaveCheck[S].setAttribute('value',"" + S + "");
        var saved=readCookie('mycookie');
    	if(! saved){ // no saved sessions (null)
    	SaveCheck[S].checked=false; // if mycookie does not exist, all sessions displayed must be unchecked
    	}
    	else {
    	    if ((saved.indexOf(Sessions[S])!=-1)){
    	    SaveCheck[S].checked=true; // if session exists in BOTH sessioncookie and mycookie
    	    }
    	}    
        PlayImage[S]=document.createElement('img');
        PlayImage[S].src='images/bmp_play.png';    
        PlayImage[S].setAttribute('class','pointer');
        PlayImage[S].setAttribute('title','replay');
        PlayImage[S].setAttribute('alt','replay');    
        PlayImage[S].setAttribute('style','height:16px;width:16px;');
        PlayImage[S].setAttribute('onclick',"replaySession('" + type+S + "');");
        Time[S]=document.createElement('span');
        Time[S].textContent=getAMPMstring(new Date(parseInt(time))); 
        GenderPic[S]=document.createElement('img');
        GenderPic[S].src=MfImage[gender];
        GenderPic[S].setAttribute('title',MfTitAlt[gender]);
        GenderPic[S].setAttribute('alt',MfTitAlt[gender]);
        GenderPic[S].setAttribute('style','height:16px;width:16px;');
        Background[S]=document.createElement('span');
        Background[S].textContent=BG[bg];
        TypePic[S]=document.createElement('img');
        TypePic[S].src=TypeImage[type];
        TypePic[S].setAttribute('title',TypeTitAlt[type]);
        TypePic[S].setAttribute('alt',TypeTitAlt[type]);
        TypePic[S].setAttribute('style','height:16px;width:16px;');
        br=document.createElement('br');
        Sessionlist.appendChild(SaveCheck[S]);
        Sessionlist.appendChild(PlayImage[S]);  
        Sessionlist.appendChild(Time[S]);
        Sessionlist.appendChild(GenderPic[S]);
        Sessionlist.appendChild(Background[S]);
        Sessionlist.appendChild(TypePic[S]);
        Sessionlist.appendChild(br);
        }
    </script>
    In my case, sessioncookie is a list of all the "recordings" - and all get displayed - and mycookie is only a saved subset of some of those recordings.

    Now the sessioncookie listing displays with checks only against those that are also in mycookie. Perfect!

    I couldn't have figured it out without your help. Indebted.

    I have a feeling that you only want to pass the sessions position within the sorted list of sessions.
    Actually, I do need to pass the type so it loads up the correct page, but I'm amazed that you were thinking that far ahead for me! For the record:

    Code:
    <script type="text/javascript">
    function setString1(value){
    var v = value;
    parent.location.href="http://aapress.com.au/sleepfall/presets.php?" + v + ""; 
    }
    function setString3(value){
    var v = value;
    parent.location.href="http://aapress.com.au/sleepfall/random.php?" + v + "";
    }
    </script>
    <script type="text/javascript">
    function replaySession(value){ // [R, (P)1, (P)2, (P)3, (P)4, or (P)5] + [0, 1, 2, 3, or 4] or [0, 1, 2, 3, 4, 5, 6, 7, 8 or 9]
    var v = value.toString();
    var type = v.charAt(0); // session type to replay [R, 1, 2, 3, 4 or 5]
    	if (type != "R") { // preset session
    	setString1(v); // send string of 2 characters
    	}
    	else { // random session
    	setString3(v); // send string of 2 characters
    	}
    }
    </script>
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  12. #41
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    you can also do:

    replace
    Code:
        if(! saved){ // no saved sessions (null)
        SaveCheck[S].checked=false; // if mycookie does not exist, all sessions displayed must be unchecked
        }
        else {
            if ((saved.indexOf(Sessions[S])!=-1)){
            SaveCheck[S].checked=true; // if session exists in BOTH sessioncookie and mycookie
            }
        }
    with
    Code:
    SaveCheck[S].checked = (saved && saved.indexOf(Sessions[S])!=-1); // if mycookie exists AND session exists in mycookie
    Pros: much shorter code, and the entire test and setting is done within one line.
    Last edited by Lerura; 08-16-2014 at 08:36 PM.

  13. #42
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    I have discovered that the text part of the display with this method doesn't show in IE8 or less. Does it have something to do with getElementById issues?

    It's not as if we are using different name and ids.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


 
Page 3 of 3 FirstFirst 123

Posting Permissions

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