Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you Control Multiple Buttons ?????????

Status
Not open for further replies.

hodgesp

Programmer
Apr 21, 2004
32
US
I just started my first ASP project for a SQL 2000 Database.
I have successfully added some java buttons to my page and the onClick events work fine on all of them.

However I can not get the onMouseOver events to function with multiple buttons on the page. It works fine when only one button is present. I understand I need to creat some sort of an array variable. Since this is my first forray with Javascript, I don't know how to write the code to accomplish my multple button contol.

Can someone help me out with a basic array function that will allow my onMouseOver events to work on all my buttons when they are all on the page.

Thank you very many.......

 

Can you post the code you have so far, so we can see what sort of thing you are trying to do with the buttons, as well as the structure of your HTML?

Dan
 
Here is my ASP Page Code:


<%@LANGUAGE=VBSCRIPT%>
<HTML>
<HEAD>
<TITLE>"ASP WEB</TITLE>
</HEAD>
<!--->
<%
On Error Resume Next
DIM MyName
DIM UserISP
MyName="Developer"
Response.write "<sub><font color=lightgreen>Developer:</font><font color=lightblue>"&MyName&"</font><sub><br>"
%>
<BODY BGCOLOR=#003300 >
<table cellspacing="0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table1">
<TR>
<TD><IMG alt="ASP WEB" src="Graphics\WIPPLogo.jpg" height="81" width="118"></TD>
</TR>
</table>
<H1 align="center"><font color="#ffcc33">WIPPCTS WEB</font></H1>
<HR width="100%" size="1">

<!----------------------------------------------------------------------------------------------------------------->
<% 'Connection to db
' On Error Resume Next

DIM dbConn, RS1, SQLStr

Set dbConn=Server.CreateObject("ADODB.Connection") 'Set the Connection Variable
dbConn.Open Session("StrConn") 'Open Connection Variable
%>
<!----------------------------------------------------------------------------------------------------------------->

<BLOCKQUOTE>
<!--#Include File="includes\XBtns.htm"-->
<table cellspacing=".0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table3">
<tr>

<td>
<!--- Data Entry Button--->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/DEOn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/DEOff.gif'); return true;">
<IMG NAME="off" SRC="graphics/DEOff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>
</tr>
<tr>
<td>
<!--- Report Button --->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/GROn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/GROff.gif'); return true;">
<IMG NAME="off" SRC="graphics/GROff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>
</tr>
<tr>
<td>
<!--- Browse Button --->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/BROn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/BROff.gif'); return true;">
<IMG NAME="off" SRC="graphics/BROff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>

</tr>
</table>
</BLOCKQUOTE>

<%
UserISP = Request.ServerVariables("Remote_Addr")
%>

</BODY>
</HTML>

============================================================
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
============================================================
HERE is my Javascript page include file code:


<HTML>
<HEAD>
<!--- this code works when you place on.gif and off.gif into your images folder --->
<!--- this is the Java Button preload script --->
<SCRIPT TYPE="text/javascript">
<!---
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src = changeImages.arguments[i+1];
}
}
}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
on = newImage("graphics/var.gif");
preloadFlag = true;
}
}

// -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" ONLOAD="preloadImages();">
</BODY>
</HTML>
 
hodgesp,
When posting code, give us a copy of the 'view source' from the browser. This allows us to paste it into a new html file so that we can see the same thing you're seeing.

-kaht

banghead.gif
 
Well, technically that is what I did. I was able to select the code paste it into textpad then reselect it into the .Net editor, save it as a new page and was able to pull it up in the browser. If there is a way to edit the font and size when posting here let me know because when I tried to paste the code again it looked the same.

Sorry for the confusion.

My main question is stil that I need to know how to write an array function in javascript to allow the onMouseOver of buttons on my ASP page to operate.




 
hodgesp said:
Well, technically that is what I did
Uhm.... no it's not. I want a view source from your internet browser, not the source code from your development platform. I can't run your source code because obviously I can't access the database on your intranet. I can however paste all the html/javascript passed to the browser after the asp is compiled, and then I can see the same thing you're seeing when you try to run your page.

-kaht

banghead.gif
 
Well then here:

<HTML>
<HEAD>
<TITLE>"ASP WEB</TITLE>
</HEAD>
<!--->
<sub><font color=lightgreen>Developer:</font><font color=lightblue>Developer</font><sub><br>
<BODY BGCOLOR=#003300 >
<table cellspacing="0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table1">
<TR>
<TD><IMG alt="WEB" src="Graphics\Logo.jpg" height="81" width="118"></TD>
</TR>
</table>
<H1 align="center"><font color="#ffcc33">WIPPCTS WEB</font></H1>
<HR width="100%" size="1">

<!----------------------------------------------------------------------------------------------------------------->

<!----------------------------------------------------------------------------------------------------------------->

<BLOCKQUOTE>
<HTML>
<HEAD>
<!--- this code works when you place on.gif and off.gif into your images folder --->
<!--- this is the Java Button preload script --->
<SCRIPT TYPE="text/javascript">
<!---
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src = changeImages.arguments[i+1];
}
}
}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
on = newImage("graphics/var.gif");
preloadFlag = true;
}
}

// -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" ONLOAD="preloadImages();">
</BODY>
</HTML>

<table cellspacing=".0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table3">
<tr>

<td>
<!--- Data Entry Button--->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/DEOn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/DEOff.gif'); return true;">
<IMG NAME="off" SRC="graphics/DEOff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>
</tr>
<tr>
<td>
<!--- Report Button --->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/GROn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/GROff.gif'); return true;">
<IMG NAME="off" SRC="graphics/GROff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>
</tr>
<tr>
<td>
<!--- Browse Button --->
<A HREF="#" onClick="parent.location=' ONMOUSEOVER="changeImages('off', 'graphics/BROn.gif'); return true;" ONMOUSEOUT="changeImages('off', 'graphics/BROff.gif'); return true;">
<IMG NAME="off" SRC="graphics/BROff.gif" BORDER="0" ALT=""></A>
<!--- this is the end of the button image information --->
</td>

</tr>
</table>
</BLOCKQUOTE>



</BODY>
</HTML>
 
Well.... immediately I saw a few things that should be changed. For starters, all of your images have the same name. Second, you're defining the changeImages function w/o any parameters, and that's just confusing. Third, put the onmouseover and onmouseout elements in the img tags instead of the anchor tags. This will allow you to use the this reference when calling the functions, and since the img's are what you're wanting to change anyway, it just makes more sense that way. I modified your code like so and it worked for me:
By the way, this code was a wreck, you had multiple opening and closing body/head tags where you didn't need them and the indentation made the code extremely hard to read, I cleaned all that up for you
Code:
<HTML>
<HEAD>
<TITLE>"ASP WEB</TITLE>
<!--- this code works when you place on.gif and off.gif into your images folder --->
<!--- this is the Java Button preload script --->
<SCRIPT TYPE="text/javascript">
function newImage(arg) {
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImages(obj, newsrc) {
   if (document.images && (preloadFlag == true)) {
      obj.src = newsrc;
   }
}

var preloadFlag = false;
function preloadImages() {
   if (document.images) {
      on = newImage("graphics/var.gif");
      preloadFlag = true;
   }
}

</SCRIPT>
</HEAD>
<BODY BGCOLOR="#003300" ONLOAD="preloadImages();">
<sub><font color=lightgreen>Developer:</font><font color=lightblue>Developer</font><sub><br>
<BLOCKQUOTE> 
<table cellspacing="0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table1">
   <TR>
      <TD><IMG alt="WEB" src="Graphics\Logo.jpg"  height="81" width="118"></TD>
   </TR>
</table>
<H1 align="center"><font color="#ffcc33">WIPPCTS WEB</font></H1>
<HR width="100%" size="1">
<table cellspacing=".0" cellpadding="0" border="0" ALIGN="center" VALIGN="CENTER" NOWRAP ID="Table3">
   <tr>
      <td>
         <!--- Data Entry Button--->
         <A HREF="#" onClick="parent.location='[URL unfurl="true"]http://server/web/EntryScreen.asp';">[/URL]
         <IMG NAME="off1" SRC="graphics/DEOff.gif" BORDER="0" ALT="" ONMOUSEOVER="changeImages(this, 'graphics/DEOn.gif'); return true;" ONMOUSEOUT="changeImages(this, 'graphics/DEOff.gif'); return true;"></A> 
         <!--- this is the end of the button image information --->
      </td>
   </tr>
   <tr>
      <td>
         <!--- Report Button --->
         <A HREF="#" onClick="parent.location='[URL unfurl="true"]http://server/web/RptWriter.asp';">[/URL]
         <IMG NAME="off2" SRC="graphics/GROff.gif" BORDER="0" ALT="" ONMOUSEOVER="changeImages(this, 'graphics/GROn.gif'); return true;" ONMOUSEOUT="changeImages(this, 'graphics/GROff.gif'); return true;"></A> 
         <!--- this is the end of the button image information --->
      </td>
   </tr>
   <tr>
      <td>
         <!--- Browse Button --->
         <A HREF="#" onClick="parent.location='[URL unfurl="true"]http://roswell/ctsweb/BrowseWriter.asp';">[/URL]
         <IMG NAME="off3" SRC="graphics/BROff.gif" BORDER="0" ALT="" ONMOUSEOVER="changeImages(this, 'graphics/BROn.gif'); return true;" ONMOUSEOUT="changeImages(this, 'graphics/BROff.gif'); return true;"></A> 
         <!--- this is the end of the button image information --->
      </td>            
   </tr>    
</table>
</BLOCKQUOTE>
</BODY>
</HTML>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top