eddyperu
asked on
How can I change an image from a button that have been set in the Master Page?
Hi experts!
This question is a little complicated so please be patience. This program was already written so I can not change the arquitecture.
I have a Master page(FirstMaster.master) that have 4 button that are actually  images wrapped in an anchors so I can use the rollover effect.
 I am sending the code of this buttons, by the way they have a script function that allow them to have the rollover and rollout effect.
The FirstMaster.master have a ContentPlaceHolder called "MainContent",(You mignt be wonder at this time what is NavigationContent.aspx that the buttons refer, I am getting there...).
Inside the ContentPlaceHolder(MainCon tent)  from "c.master"  there is a MasterPage Called  "SecondMaster.master" page.
The SecondMaster.master page have a Contentplaceholder called "MarqueecontentPlaceHolder ".
Inside this contentplaceholder (MarqueeContentPlaceHolder ) is where we can find the "NavigationContent.aspx" Â page.
The NavigationContent.aspx content  information that is pulled form the database. The information is different depending of the "contentid"  that I set in the anchors(buttons from the FirstMaster.master page):
 <a href="NavigationContent.as px?content id=Tree" .................<img ........../.> </a>
There are three different "contentid" :house, car, tree.
THe program works great, there is no problem with the program but I want to add some features that have to do with the buttons in the FirstMaster.master when these are click.
QUESTION : The buttons have the rollover and rollout effect. What I want to do is that the code be smart to identify in which page they are so they can change the image of that button to on instead of OFF.
If you see in the code of my buttons there are two picture one of them is ####.ON and the other is  ####. OFF.
When the client click one of the buttons I want that the program can recognized that this one is the one that the client have clicked so lets go and change the picture of that page to ###.ON and leave it like that until the client click another button.
I have tried everything but it doesn't work, even I hardcoded the buttons but everytime the page doesn't recognized the code or I ahve some troubles with the pictures. I really need your help in this one, thanks:
Example: If the Client CLick :
 <a href="NavigationContent.as px?content id=house"
 onmouseover="swap('menu_ho use','imag es/house_o n.png')"
 onmouseout="swap('menu_hou se','image s/house_of f.jpg')">
  <img id="menu_house" src="images/house_off.jpg" />
 </a>
The menu of the buttons in the house page will looks like this:
  house_on.jpg   //   car_off.jpg  //  tree_off.jpg   Â
Â
Thanks for your help!!!
This question is a little complicated so please be patience. This program was already written so I can not change the arquitecture.
I have a Master page(FirstMaster.master) that have 4 button that are actually  images wrapped in an anchors so I can use the rollover effect.
 I am sending the code of this buttons, by the way they have a script function that allow them to have the rollover and rollout effect.
The FirstMaster.master have a ContentPlaceHolder called "MainContent",(You mignt be wonder at this time what is NavigationContent.aspx that the buttons refer, I am getting there...).
Inside the ContentPlaceHolder(MainCon
The SecondMaster.master page have a Contentplaceholder called "MarqueecontentPlaceHolder
Inside this contentplaceholder (MarqueeContentPlaceHolder
The NavigationContent.aspx content  information that is pulled form the database. The information is different depending of the "contentid"  that I set in the anchors(buttons from the FirstMaster.master page):
 <a href="NavigationContent.as
There are three different "contentid" :house, car, tree.
THe program works great, there is no problem with the program but I want to add some features that have to do with the buttons in the FirstMaster.master when these are click.
QUESTION : The buttons have the rollover and rollout effect. What I want to do is that the code be smart to identify in which page they are so they can change the image of that button to on instead of OFF.
If you see in the code of my buttons there are two picture one of them is ####.ON and the other is  ####. OFF.
When the client click one of the buttons I want that the program can recognized that this one is the one that the client have clicked so lets go and change the picture of that page to ###.ON and leave it like that until the client click another button.
I have tried everything but it doesn't work, even I hardcoded the buttons but everytime the page doesn't recognized the code or I ahve some troubles with the pictures. I really need your help in this one, thanks:
Example: If the Client CLick :
 <a href="NavigationContent.as
 onmouseover="swap('menu_ho
 onmouseout="swap('menu_hou
  <img id="menu_house" src="images/house_off.jpg"
 </a>
The menu of the buttons in the house page will looks like this:
  house_on.jpg   //   car_off.jpg  //  tree_off.jpg   Â
Â
Thanks for your help!!!
These are the buttons that I was talking about inside FirstMaster.master:
<td>
<a href="NavigationContent.aspx?contentid=house"
onmouseover="swap('menu_house','images/house_on.png')"
onmouseout="swap('menu_house','images/house_off.jpg')">
<img id="menu_house" src="images/house_off.jpg" />
</a>
</td>
<td>
<a href="NavigationContent.aspx?contentid=car"
onmouseover="swap('menu_car,'images/car_on.png')"
onmouseout="swap('menu_car','images/car_off.jpg')">
<img id="menu_car" src="images/car_off.jpg" />
</a>
</td>
<td>
<a href="NavigationContent.aspx?contentid=Tree"
onmouseover="swap('menu_Tree,'images/Tree_on.png')"
onmouseout="swap('menu_Tree,'images/Tree_off.jpg')">
<img id="menu_Tree" src="images/Tree_off.jpg" />
</a>
</td>
By the way, did you notice the missing single quotes in Tree link?
ASKER
HI ,
Thanks but It didn't work I have an error "Undefined" for the img variable, This is the code that I wrote:
   var content=location.search.sp lit('conte ntid=');   Â
   if(content.length>1){
    var img = document.images["menu_"+(c ontent[1]+ "&").split ("&")[0]];  //would you mind to explain me
                                                           //this line a little bit more?
    alert(img);  // It says Undefined
    img.src = img.src.replace(".","_on." );
  }
The URL for House  looks like this:
http://localhost/###/#######.aspx?contentid=House
This is the real example, you can se that I don't have a "_off" for the buttons that are off, sorry about that:
<td>
 <a href="NavigationContent.as px?content id=car"
 onmouseover="swap('menu_ca r,'images/ car_on.png ')"
 onmouseout="swap('menu_car ','images/ car.jpg')" >
  <img id="menu_car" src="images/car.jpg" />
 </a>
</td>
ps:Yes,I notice the missing single quotes but that was a typing error, sorry about that too.!
THanks
Thanks but It didn't work I have an error "Undefined" for the img variable, This is the code that I wrote:
   var content=location.search.sp
   if(content.length>1){
    var img = document.images["menu_"+(c
                                                           //this line a little bit more?
    alert(img);  // It says Undefined
    img.src = img.src.replace(".","_on."
  }
The URL for House  looks like this:
http://localhost/###/#######.aspx?contentid=House
This is the real example, you can se that I don't have a "_off" for the buttons that are off, sorry about that:
<td>
 <a href="NavigationContent.as
 onmouseover="swap('menu_ca
 onmouseout="swap('menu_car
  <img id="menu_car" src="images/car.jpg" />
 </a>
</td>
ps:Yes,I notice the missing single quotes but that was a typing error, sorry about that too.!
THanks
ASKER
The error message in javascript says : Â ' img' Â is null or not an object
Thanks for your help
Thanks for your help
ASKER
This is the real example with the real code for the buttons, the one that I wrote above were example, I hope that this can help:
              <td align="right">
                <a href="NavigationContent.as px?content id=Reports Page"
                 onmouseover="swap('menu_Re portingToo ls','image s/Reportin gTools4_on .png')"
                 onmouseout="swap('menu_Rep ortingTool s','images /ReportigT ools4.jpg' )">
                 <img id="menu_ReportingTools" src="images/ReportigTools4 .jpg" alt="Report page" style="border: 0px" />
                </a>
              </td>
              <td align="right">
                <a href="NavigationContent.as px?content id=PolicyP rocedures"
                 onmouseover="swap('menu_Po licyProced ures','ima ges/Polici esProcedur e4_on.png' )"
                 onmouseout="swap('menu_Pol icyProcedu res','imag es/Policie sProcedure 4.jpg')">
                 <img id="menu_PolicyProcedures" src="images/PoliciesProced ure4.jpg" alt="Policies & Procedures" style="border: 0px" />
                </a>
              </td>
             Â
              <td align="right" onclick="__doPostBack('upd atePanel12 ', '');">
                <a href="NavigationContent.as px?content id=OnlineL ibrary"
                 onmouseover="swap('menu_On lineLibary ','images/ OnlineLibr ary4_on.pn g')"
                 onmouseout="swap('menu_Onl ineLibary' ,'images/O nlineLibra ry4.jpg')" >
                 <img id="menu_OnlineLibary" src="images/OnlineLibrary4 .jpg" alt="Online Library" style="border: 0px" />
                </a>
              </td>thanks
              <td align="right">
                <a href="NavigationContent.as
                 onmouseover="swap('menu_Re
                 onmouseout="swap('menu_Rep
                 <img id="menu_ReportingTools" src="images/ReportigTools4
                </a>
              </td>
              <td align="right">
                <a href="NavigationContent.as
                 onmouseover="swap('menu_Po
                 onmouseout="swap('menu_Pol
                 <img id="menu_PolicyProcedures"
                </a>
              </td>
             Â
              <td align="right" onclick="__doPostBack('upd
                <a href="NavigationContent.as
                 onmouseover="swap('menu_On
                 onmouseout="swap('menu_Onl
                 <img id="menu_OnlineLibary" src="images/OnlineLibrary4
                </a>
              </td>thanks
Check this:
   var content=location.search.sp lit('conte ntid='); // search for contentid= in the URL
   if(content.length>1){ // if found
    // var img = document.images["menu_"+(c ontent[1]+ "&").split ("&")[0]];
// can be written like this:
    var theParam = content[1]; // take second element from split() array
    theParam + "&";
    theParam = theParam.split("&"); // make a new array
    theParam = theParam[0];  // take first element
    alert(theParam) // should alert: Home
    img = document.images["menu_" + theParam];
    alert(img);  // It says Undefined if img without: name="menu_Home"
    img.src = img.src.replace(/(_off)?\. /i,"_on.") ;
  }
   var content=location.search.sp
   if(content.length>1){ // if found
    // var img = document.images["menu_"+(c
// can be written like this:
    var theParam = content[1]; // take second element from split() array
    theParam + "&";
    theParam = theParam.split("&"); // make a new array
    theParam = theParam[0];  // take first element
    alert(theParam) // should alert: Home
    img = document.images["menu_" + theParam];
    alert(img);  // It says Undefined if img without: name="menu_Home"
    img.src = img.src.replace(/(_off)?\.
  }
I just see you mix jpg and png!
<script>
var content=location.search.split('contentid=');
if(content.length>1){
var img = document.images["menu_"+(content[1]+"&").split("&")[0]];
img.src = img.src.replace(/(_off)?\.\w+$/i,"_on.png");
}
</script>
ASKER
I did that but still there is a undefined in the  img alert textbox, eventhough in my code(the last one that I sent you says : <img id="menu_ReportingTools" src="images/ReportigTools4 .jpg" alt="Report page" style="border: 0px" />)
I guess what you call "name" is the ID of the IMG which is "menu_ReportingTools":
I copy and paste  your code but still I have the undefined.
The problem is in the "img=" Â why is doing that?
thanks
I guess what you call "name" is the ID of the IMG which is "menu_ReportingTools":
I copy and paste  your code but still I have the undefined.
The problem is in the "img=" Â why is doing that?
thanks
ASKER
I added the name to <img> and to <a> but still is not working:
              <td align="right">
                <a href="NavigationContent.as px?content id=Reports Page"  name="menu_ReportingTools"
                 onmouseover="swap('menu_Re portingToo ls','image s/Reportin gTools4_on .png')"
                 onmouseout="swap('menu_Rep ortingTool s','images /ReportigT ools4.jpg' )">
                 <img id="menu_ReportingTools" name="menu_ReportingTools" src="images/ReportigTools4 .jpg" alt="Report page" style="border: 0px" />
                </a>
              </td>
thanks
              <td align="right">
                <a href="NavigationContent.as
                 onmouseover="swap('menu_Re
                 onmouseout="swap('menu_Rep
                 <img id="menu_ReportingTools" name="menu_ReportingTools"
                </a>
              </td>
thanks
ASKER
Thanks for your last code, I didn't see it.
Well I tried but still I aahve the same error:
 'img' in Null or not an object
Thanks
Well I tried but still I aahve the same error:
 'img' in Null or not an object
Thanks
I have just again tested in IE6 and FF2 and it worked.
But are you sure the img is accessed AFTER the <img> location on the page?
If you feel better with id methods, then take this:
But are you sure the img is accessed AFTER the <img> location on the page?
If you feel better with id methods, then take this:
var content=location.search.split('contentid=');
if(content.length>1){
var img = document.getElementById("menu_"+(content[1]+"&").split("&")[0]);
img.src = img.src.replace(/(_off)?\.\w+$/i,"_on.png");
}
ASKER
This is the whole code for this page. This is a master page :
The ContentPlaceHolder contain different information depending of the click of the anchors. The information come from a database, but all see is seing from the codebehind.
Thanks,
The ContentPlaceHolder contain different information depending of the click of the anchors. The information come from a database, but all see is seing from the codebehind.
Thanks,
<head id="Head1" runat="server">
<title>MYPAGE</title>
<link href="StyleSheet.css" rel="Stylesheet" type="text/css" />
<link href="ContentPageTable.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="scripts/utilities.js"></script>
<script language="javascript" src="scripts/RollOverButtons.js"></script>
<script language="javascript">
var content=location.search.split('contentid=');
if(content.length>1){
var img = document.getElementById("menu_"+(content[1]+"&").split("&")[0]);
img.src = img.src.replace(/(_off)?\.\w+$/i,"_on.png");
}
//This section allow the program to preload images
var theImagesArray = "images/LLeft_Corner_Top.png;"+
"images/LTop.png;"+
"images/LRight_Corner_Top.png;"+
"images/LLeft_Side.png;"+
"images/Lright_side.png;"+
"images/LLeft_Corner_Bottom.png;"+
"images/LBottom.png;"+
"images/LRight_Corner_Bottom.png;"+
"images/ReportigTools4.jpg;"+
"images/PoliciesProcedure4.jpg;"+
"images/OnlineLibrary4.jpg;"+
"images/SimplyUNUM4.jpg;"+
"images/BCNews4.jpg;"+
"images/LinkSystem4.jpg;"+
"images/Home4.jpg;"+
"images/ReportingTools4_on.png;"+
"images/PoliciesProcedure4_on.png;"+
"images/OnlineLibrary4_on.png;"+
"images/SimplyUNUM4_on.png;"+
"images/BCNews4_on.png;"+
"images/LinkSystem4_on.png;"+
"images/Home4_on.png;"+
"images/INside_Default_picture.png;"+
"images/WelcometoBC.png;"+
"images/ReportingTools_2.jpg;"+
"images/ReportingTools_2_on.jpg;"+
"images/PoliciesProcedures_2.jpg;"+
"images/PoliciesProcedures_2_on.jpg;"+
"images/OnlineLibrary_2.jpg;"+
"images/OnlineLibrary_2_on.jpg;"+
"images/SimplyUnum_2.jpg;"+
"images/SimplyUnum_2_on.jpg;"+
"images/BCNews2.jpg;"+
"images/BCNews2_on.jpg;"+
"images/LinkSystem_2.jpg;"+
"images/LinkSystem_2_on.jpg;"+
"images/Box_FotoSection_policies.jpg;"+
"images/Back_button_on.jpg;"+
"images/Back_button.jpg;"+
"images/images/Header_box.jpg;"+
"images/images/Box_FotoSection_Pryvacyawarness.jpg;"+
"images/images/Box_FotoSection_reference_on.jpg;"+
"images/images/Box_FotoSection_reference.jpg;"+
"images/images/box_right.png;"+
"images/images/box_left.png;"+
"images/images/Policies_Header_box.jpg;"+
"images/images/Select.jpg;"+
"images/images/Bottom_box.png;"+
"images/images/Prefrief_Policies_Header_box.jpg;"+
"images/images/Box_FotoSection_on.jpg;"+
"images/images/Box_FotoSection.jpg;"+
"images/images/Box_FotoSection_Newemployee_on.jpg;"+
"images/images/Box_FotoSection_Newemployee.jpg;"+
"images/images/Box_FotoSection_marketingresources_on.jpg;"+
"images/images/Box_FotoSection_marketingresources.jpg;"+
"images/images/Box_FotoSection_planebiz_on.jpg;"+
"images/images/Travel_on.jpg;"+
"images/images/Travel.jpg;"+
"images/images/Time_on.jpg;"+
"images/images/Time.jpg;"+
"images/images/ExpenseReportButton_on.jpg;"+
"images/images/ExpenseReportButton.jpg;"
preloadImages(theImagesArray);
function beginSessionTimer()
{
timer = window.setTimeout("timeoutNotify()", <%= (Session.Timeout - 1) * 60000 %>);
document.getElementById('pleaseWait').style.display='none';
document.getElementById('pageContainer').style.display='';
heavyImage = new Image();
heavyImage.src = "New_logo_page1.png";
}
function timeoutNotify()
{
var w = 380;
var h = 70;
var l = Math.round((window.screen.width - w) / 2);
var t = Math.round((window.screen.height - h) / 2);
var opts = "left="+l+",top="+t+",width="+w+", height="+h+",scrollbars=no,toolbar=no,location=no,menubar=no,status=no,resizable=no";
wnd = window.open("SessionWarning.html?<%= Server.UrlEncode(LOGOUT_PAGE) %>", "notifyWnd", opts);
wnd.focus();
}
</script>
</head>
<body onload="beginSessionTimer()" style="margin: 0px; padding: 0px">
<form id="LINKForm" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<div id="pleaseWait" style="font-weight:bold; font-size:10px; color:#015294;
margin-top: auto;
margin-right: auto;
margin-bottom: auto;
padding: 450px 0px 0px 550px;
width: 917px;">
Please Wait... <img src="images/PageAnimation1.gif" /></div>
<div id="pageContainer" style="position:absolute; top:0;left:0; display:none">
<div id="outer" align="center">
<div style="z-index: 101; right:-145px; position: relative; top: 250px;">
<asp:Panel ID="PanelButtons" runat="server">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right">
<a href="NavigationContent.aspx?contentid=ReportsPage"
onmouseover="swap('menu_ReportingTools','images/ReportingTools4_on.png')"
onmouseout="swap('menu_ReportingTools','images/ReportigTools4.jpg')">
<img id="menu_ReportingTools" src="images/ReportigTools4.jpg" alt="Report page" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="NavigationContent.aspx?contentid=PolicyProcedures"
onmouseover="swap('menu_PolicyProcedures','images/PoliciesProcedure4_on.png')"
onmouseout="swap('menu_PolicyProcedures','images/PoliciesProcedure4.jpg')">
<img id="menu_PolicyProcedures" src="images/PoliciesProcedure4.jpg" alt="Policies & Procedures" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="NavigationContent.aspx?contentid=OnlineLibrary"
onmouseover="swap('menu_OnlineLibary','images/OnlineLibrary4_on.png')"
onmouseout="swap('menu_OnlineLibary','images/OnlineLibrary4.jpg')">
<img id="menu_OnlineLibary" src="images/OnlineLibrary4.jpg" alt="Online Library" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="NavigationContent.aspx?contentid=SimplyUnum"
onmouseover="swap('menu_SimplyUnum','images/SimplyUNUM4_on.png')"
onmouseout="swap('menu_SimplyUnum','images/SimplyUNUM4.jpg')">
<img id="menu_SimplyUnum" src="images/SimplyUNUM4.jpg" alt="Simply UNUM" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="NavigationContent.aspx?contentid=BCNews"
onmouseover="swap('menu_BCNews','images/BCNews4_on.png')"
onmouseout="swap('menu_BCNews','images/BCNews4.jpg')">
<img id="menu_BCNews" src="images/BCNews4.jpg" alt="Home" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="LinkSystem.aspx"
onmouseover="swap('menuLinkSystem','images/LinkSystem4_on.png')"
onmouseout="swap('menuLinkSystem','images/LinkSystem4.jpg')">
<img id="menuLinkSystem" src="images/LinkSystem4.jpg" alt="Link System" style="border: 0px" />
</a>
</td>
<td align="right">
<a href="NavigationContent.aspx?contentid=Home"
onmouseover="swap('menu_Home','images/Home4_on.png')"
onmouseout="swap('menu_Home','images/Home4.jpg')">
<img id="menu_Home" src="images/Home4.jpg" alt="Home" style="border: 0px" />
</a>
</td>
</tr>
</table>
</asp:Panel>
</div>
<div id="LabelName" align="left">
<upc:LabelName ID="LabelNameShow" runat="server" />
</div>
<upc:PageHeader ID="PageHeader" runat="server" />
<table border="0" cellpadding="0" cellspacing="0" width="980px">
<tr>
<td width="10px" height="20px" background="images/LLeft_Corner_Top.png">
</td>
<td width="20px" height="20px" background="images/LTop.png" >
</td>
<td width="10px" height="20px" background="images/LRight_Corner_Top.png">
</td>
</tr>
<tr>
<td width="10px" height="20px"background="images/LLeft_Side.png">
</td>
<td valign="top">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</td>
<td background="images/Lright_side.png">
</td>
</tr>
<tr>
<td width="10px" height="30px" background="images/LLeft_Corner_Bottom.png">
</td>
<td width="980px" height="30px" background="images/LBottom.png" valign="middle">
<uc1:PageFooter id="PageFooter" runat="server">
</uc1:PageFooter>
</td>
<td width="10px" height="30px" background="images/LRight_Corner_Bottom.png">
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
Put my script at the end of page.
Like this:
Like this:
</form>
<script>
var content=location.search.split('contentid=');
if(content.length>1){
var img = document.getElementById("menu_"+(content[1]+"&").split("&")[0]);
img.src = img.src.replace(/(_off)?\.\w+$/i,"_on.png");
}
</script>
</body>
</html>
ASKER
HI, thanks..
It works...but still there are some errors:
1) The "Online library" and the "Report Page" have errors, the anchor doesn't change to the off one .
2) The swap function(to change the picture to the mouse over) still works even for the anchors where the page are set, changing the picture everytime that the mouse is over.
Example:
If I am in home" when I click it , the image change(GREAT) but when I put my mouse over that button is triggering the swap function.
I truly appreciate your help!!
thanks
sp: Why this code is working at the end of the page and  not in the beggining?
It works...but still there are some errors:
1) The "Online library" and the "Report Page" have errors, the anchor doesn't change to the off one .
2) The swap function(to change the picture to the mouse over) still works even for the anchors where the page are set, changing the picture everytime that the mouse is over.
Example:
If I am in home" when I click it , the image change(GREAT) but when I put my mouse over that button is triggering the swap function.
I truly appreciate your help!!
thanks
sp: Why this code is working at the end of the page and  not in the beggining?
ASKER
I found something interesting:
THe Online library and the report page is not reaching the Javascript at the end of the page, the res of the anchors are reaching it.
TESTED:
I created an alert box for img.src but after clicking the online library and the report page none of them reach this script.
Why is that?
THe Online library and the report page is not reaching the Javascript at the end of the page, the res of the anchors are reaching it.
TESTED:
I created an alert box for img.src but after clicking the online library and the report page none of them reach this script.
Why is that?
ASKER
Never  mind  , erase the last comment. I was wrong!
The image changes to _on but the <a> tage still has it event handlers active.
Open for disabling <a> tag handlers a new question and put a reference of that question here.
sp: Why this code is working at the end of the page and  not in the beggining?
Answer: http:#22261404
I do not understand the question about Online library, sorry.
Open for disabling <a> tag handlers a new question and put a reference of that question here.
sp: Why this code is working at the end of the page and  not in the beggining?
Answer: http:#22261404
I do not understand the question about Online library, sorry.
Perhaps if you do not read it: the script has to be AFTER the <img> tags because the script can access only tags that are already rendered on the page to the point where the scipt is located.
You could put my script also into the onLoad event handler because at that time are all <img>s rendered and accessible by script. But to avoid onLoad event complication I made an independant script. Sorry if that confuses you.
You could put my script also into the onLoad event handler because at that time are all <img>s rendered and accessible by script. But to avoid onLoad event complication I made an independant script. Sorry if that confuses you.
ASKER
I the last code that I sent you there are 5 anchors, 2 of them  named "online library" and "Report page" throw an error script in which the img is NUL. The other anchors work great.
I was wondering why?, Thanks
I was wondering why?, Thanks
Checkand see:
<a href="NavigationContent.as px?content id=Reports Page" Â <img id="menu_ReportingTools"
<a href="LinkSystem.aspx" Â <img id="menuLinkSystem"
That two cannot work.
<a href="NavigationContent.as
<a href="LinkSystem.aspx" Â <img id="menuLinkSystem"
That two cannot work.
ASKER
Hi,
The LynkSystem doesn't need to work, no porblem with that one bu the
Reportpage and the Online Library should work, why?
Thank you
The LynkSystem doesn't need to work, no porblem with that one bu the
Reportpage and the Online Library should work, why?
Thank you
ASKER
ooh..I see!!
OK, I did not see it either at first look.
Look again:
Look again:
<a href="NavigationContent.aspx?contentid=OnlineLibrary"
<img id="menu_OnlineLibary"
ASKER
Is there a way to be more flexible wiht this script...
Something to tell that if theFirst letter of:
 contentID= star with "L" do this( img.src = img.src.replace(/(_off)?\. \w+$/i,"_o n.png");)
 or if start with "O" do this( img.src = img.src.replace(/(_off)?\. \w+$/i,"_o n.png");) ,
 or if star with "S" do this(  img.src = img.src.replace(/(_off)?\. \w+$/i,"_o n.png");)
Sorry i don't know if this need to be another question....I can create aquestion for this...if you want me to.
Thanks
Something to tell that if theFirst letter of:
 contentID= star with "L" do this( img.src = img.src.replace(/(_off)?\.
 or if start with "O" do this( img.src = img.src.replace(/(_off)?\.
 or if star with "S" do this(  img.src = img.src.replace(/(_off)?\.
Sorry i don't know if this need to be another question....I can create aquestion for this...if you want me to.
Thanks
What is the difference in L O and S, I do not see it?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Well,
The issue is that the contentID is going to change not only with the 5 anchors that you have seen.
It is a little complicated trying to explain it but here it goes:
Clicking the different anchors will pull templates that are in my database. This templates or pages are set in the contentplaceholder of this master page. BUT inside those pages there are other buttons that  will change the context of the contentplaceholder of the master page and also the ContentID.
 It can be called the grandkids of the master page:
For example:
Clickin the anchor in the master page  "BC NEws" its URL will be like this:
URL:http://localhost/LINK/NavigationContent.aspx?contentid=BCNews
Inside this page(BC News) there is a button "CurrentEvent" When I clicked, the contentID changes to:
URL: http://localhost/LINK/navigationcontent.aspx?contentid=BCNewsCurrentEvents
There is also another button called "Updates" When I clicked, the contentId will change to :
Thisis hte URL: http://localhost/LINK/navigationcontent.aspx?contentid=BCUpdates
The other anchors behave in the same way, they have children that start with the name of the ID from the first anchor in the master page and add the name of the pages.
So I was thinking If I can let the scrit know that the contentID have  the letter "B" at the beggining, it doesn't matter what is the rest of the word, I can tell to the program to change the BCNews picture to the one that is on(The code that you wrote about replacing the image with the active one):
        var img = document.getElementById("m enu_"+(con tent[1]+"& ").split(" &")[0]);    Â
        img.src = img.src.replace(/(_off)?\. \w+$/i,"_o n.png");
is this make sence?Thanks
The issue is that the contentID is going to change not only with the 5 anchors that you have seen.
It is a little complicated trying to explain it but here it goes:
Clicking the different anchors will pull templates that are in my database. This templates or pages are set in the contentplaceholder of this master page. BUT inside those pages there are other buttons that  will change the context of the contentplaceholder of the master page and also the ContentID.
 It can be called the grandkids of the master page:
For example:
Clickin the anchor in the master page  "BC NEws" its URL will be like this:
URL:http://localhost/LINK/NavigationContent.aspx?contentid=BCNews
Inside this page(BC News) there is a button "CurrentEvent" When I clicked, the contentID changes to:
URL: http://localhost/LINK/navigationcontent.aspx?contentid=BCNewsCurrentEvents
There is also another button called "Updates" When I clicked, the contentId will change to :
Thisis hte URL: http://localhost/LINK/navigationcontent.aspx?contentid=BCUpdates
The other anchors behave in the same way, they have children that start with the name of the ID from the first anchor in the master page and add the name of the pages.
So I was thinking If I can let the scrit know that the contentID have  the letter "B" at the beggining, it doesn't matter what is the rest of the word, I can tell to the program to change the BCNews picture to the one that is on(The code that you wrote about replacing the image with the active one):
        var img = document.getElementById("m
        img.src = img.src.replace(/(_off)?\.
is this make sence?Thanks
It make sence and only thing that you have to adjust is the number of characters from contentid parameter that you want to be matched to menu_id id. I have choosen three characters to be significant. You can reduce them to two or one.
At this point:
var theID = new RegExp("_"+contentID[1].su bstr(0,3), "i"); // reduce 3 to 2 or 1
At this point:
var theID = new RegExp("_"+contentID[1].su
ASKER
Thanks it works great!
I know that this cna be anoying but would you mind to tell me how you did it, I mean comment the code. I wish to be like you one of this days and learn frrom a genius like you will help me so much!!..
If you don't have time do not worry about that , you get my points..! :)
I know that this cna be anoying but would you mind to tell me how you did it, I mean comment the code. I wish to be like you one of this days and learn frrom a genius like you will help me so much!!..
If you don't have time do not worry about that , you get my points..! :)
I understand your need but really RegExp is not explained in two words.
Basically I fetch three characters from the contentid parameter and make a Regular Expression. RegExp do have the power to match many variations of one expression.
With that RegExp I loop trough all document.images elements and look for matching ids. You see?
Basically I fetch three characters from the contentid parameter and make a Regular Expression. RegExp do have the power to match many variations of one expression.
With that RegExp I loop trough all document.images elements and look for matching ids. You see?
ASKER
Excellent... I think I get it!
By the way this is the addres about my problem with <a> handler event, how to stop them. I will really appreciate if you can give it a look, you are the perfect match to help me with this question because you know my code, thank you so much:
https://www.experts-exchange.com/questions/23660679/How-can-I-disabe-a-tag-handlers.html
What do you think?
Thanks;
By the way this is the addres about my problem with <a> handler event, how to stop them. I will really appreciate if you can give it a look, you are the perfect match to help me with this question because you know my code, thank you so much:
https://www.experts-exchange.com/questions/23660679/How-can-I-disabe-a-tag-handlers.html
What do you think?
Thanks;
ASKER
One more question before to close this forum:
in this line:
  var theID = new RegExp("_"+contentID[1].su bstr(0,1), "i");
 why do you add the ("_",.......... ,"i")?
Do I need them for somthing?
 By the way now I understand RegExp.Thank yopu soooooooooo much!
in this line:
  var theID = new RegExp("_"+contentID[1].su
 why do you add the ("_",.......... ,"i")?
Do I need them for somthing?
 By the way now I understand RegExp.Thank yopu soooooooooo much!
ASKER
MAn, this guy is a Genius.........make coding more fun! :) thank you so much Zwonko
The i modifier advises the RegExp to be character case Insensitive.
Here more details: http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx
Here more details: http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx
Open in new window