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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post

    Msg value if else

    I suspect my reasoning if faulty.
    I have a button that if you click it sends File, ID, Msg to my javascript page.

    I want my javascript function to read the content of Msg and if it X I want it to hide divs one to nine and pull the information up for content ten.

    However I am getting function is not defined.
    I have put an alert for Msg in my script which works fine if I delete everything else so I suspect my "if else" is to blame. However I've played around with the "corrections" I could think of and am getting nowhere.

    My code is:
    Code:
    function loadMultiTab(File, ID, Msg){
    alert(Msg);
    if(Msg=='BestWorse'){
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='Bookmark'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='Forums'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='Threads'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='MarketPlace'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='Suggestions'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    	loadXMLDoc('getHide.php','txtHintMiniTips');
    }else if(Msg=='Tips'){
    	loadXMLDoc('getHide.php','txtHintMiniBestWorst');
    	loadXMLDoc('getHide.php','txtHintMiniBookmark');
    	loadXMLDoc('getHide.php','txtHintMiniForums');
    	loadXMLDoc('getHide.php','txtHintMiniThreads');
    	loadXMLDoc('getHide.php','txtHintMiniMarketPlace');
    	loadXMLDoc('getHide.php','txtHintMiniSuggestions');
    };
    
    	chokecherry = setInterval (function (){loadXMLDoc(File, ID)},500);
    }
    Any help would be appreciated.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    If I supply a dummy implementation of loadXMLDoc it works for me:
    Code:
    function loadXMLDoc(f,t )
    { 
        alert("in loadXMLDoc: " + f + ", " + t );
    }
    Maybe you should try showing us a live URL where it's not working?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    I am not sure to understand...
    Are 'txtHintMiniBookmark', 'txtHintMiniForums'... callback functions ?
    Then removing the quotes will solve your problem !

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Julien: I'm not sure, but I *think* that the loadXMLDoc( ) function, with two arguments, is accepting the name of an XML file (or, in this case, a PHP page that *returns* and XML file) and then the name (id) of some tag to look for in that XML.

    That is, the XML file probably contains something like:
    Code:
    <sections>
       <txtHintMiniBookmark>...</txtHintMiniBookmark>
       <txtHintMiniForums>...</txtHintMiniForums>
       ... etc. ...
    </sections>
    So the code is asking to load those sections, in the order given, from the XML file/pseudo-file. *PROBABLY* using AJAX (possible SJAX) to do the loading.

    If so, it's a really really crappy way to do this. As it means that on each call the AJAX code has to load in the entire XML and then parse it and then use only the part in the give section. (It might mean that the PHP code will only RETURN that one section, but that's only marginally better.)

    Ugh.

    But we won't know until "Jenny" (if I recall correctly, that's a pseudonym) responds.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Jenny Dithe (07-02-2013)

  • #5
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    216
    Thanks
    0
    Thanked 29 Times in 27 Posts
    Thanks you. I do not use XML and I thought to an ajax call...

  • #6
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    That's it exactly. Sorry for not giving enough information I am always worried about bombarding or complicating.

    So my main page is:
    Code:
    							<input type="button" class="button5" value="Best Worst" onclick="loadMultiTab('getMainBestWorst.php','txtHintESD', 'BestWorse'))">
    								<div id="txtHintMiniBestWorst"></div>
    							<input type="button" class="button5" value="Bookmark" onclick="loadMultiTab('getLoadBookmark.php','txtHintESD', 'Bookmark');createGMapFromAddress()">
    								<div id="txtHintMiniBookmark"></div>
    							<input type="button" class="button5" value="Forums" onclick="loadMultiTab('getThisForum.php','txtHintESD' 'Forums')">
    								<div id="txtHintMiniForums"></div>
    							<input type="button" class="button5" value="Threads" onclick="loadMultiTab('getMainThreads.php','txtHintESD', 'Threads')">
    								<div id="txtHintMiniThreads"></div>
    							<input type="button" class="button5" value="Market Place" onclick="loadMultiTab('getMainMarketPlace.php','txtHintESD', 'MarketPlace')">
    								<div id="txtHintMiniMarketPlace"></div>
    							<input type="button" class="button5" value="Suggestions" onclick="loadMultiTab('FILEDisclaimer.php','txtHintESD', 'Suggestions')">
    								<div id="txtHintMiniSuggestions"></div>
    							<input type="button" class="button5" value="Tips" onclick="loadMultiTab('TipsSubList.php','txtHintMiniTips', 'Tips')">
    								<div id="txtHintMiniTips"></div>
    And when you click on a button I want a list of sub options (buttons to be displayed).
    Which is easy to do through the loadXMLDoc function:
    Code:
    
    function loadXMLDoc(File,ID){
    var xmlhttp; 
    
    if (window.XMLHttpRequest)  {
      xmlhttp=new XMLHttpRequest();
      }
    else {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    
    xmlhttp.onreadystatechange=function(){
      if (xmlhttp.readyState==4 && xmlhttp.status==200){
        document.getElementById(ID).innerHTML=xmlhttp.responseText;
        }
      }
    
    xmlhttp.open("POST",File,true);
    xmlhttp.send();
    }
    However I get left with a long list of buttons which looks messy. So what I am trying to do is if you click on one button then the sub buttons show for that theme, but for the other themes any previously opened buttons aren't shown.

    I know I could do css display but I thought the number of sub buttons may lengthen the time to load the page and I thought there might be a more sophisticated way of doing it.

    But perhaps that is best??

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Tough call.

    How big *is* the page with all possible sub buttons in there?

    If it's under 200KB or so, I'd go that route and forget about the dynamic loading.

    After all, just one or two JPG images will easily be more than 200KB and you wouldn't omit images just because of size, would you?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Jenny Dithe (07-02-2013)

  • #8
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    Thanks, I should probably go that way and see if there is a problem rather than making things more complicated by anticipating one (and at least I know how to do that). It's no where close to 200KB at the moment so I'll go the display route.

    Appreciate you advice.

  • #9
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    I'm a newbie, but isn't the function "loadMultiTabs"? And under that are the tests for which other function to call?
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by jerry62704 View Post
    I'm a newbie, but isn't the function "loadMultiTabs"?
    ??? Why do you say that?

    From her first post:
    Code:
    function loadMultiTab(File, ID, Msg){
    From post #6:
    Code:
    <input type="button" class="button5" value="Market Place"
     onclick="loadMultiTab('getMainMarketPlace.php','txtHintESD', 'MarketPlace')">
    I don't see loadMultiTabs any place.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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