tomjonesrocks
12-05-2003, 07:17 PM
Hello everyone--
I'm trying to do some javascipt that shows/hides a form field by clicking an image. When the user starts off, the image is a "+". When the image is clicked, I want the image to change to a "-", and then go back to a "+" when clicked again. In other words, go back and forth between "+" and "-".
I'm halfway there. The code I created hides and shows the form field, and when the button is clicked initially it swaps the image. Unfortunately, I don't know how to set up a loop so it calls the "+" image the next time. After it swaps once, it's done and won't swap anymore.
Here's my code--this is probably very easy for someone experienced with this. Any help would be appreciated! Thanks!
(this code works-show/hide)
<script LANGUAGE="JavaScript">
<!--
var noteVisible = false;
function showNote(branch) {
showHide(branch);
if (noteVisible)
noteVisible = false;
else {
noteVisible = true;
}
}
//-->
</SCRIPT>
(this code does not swap the images the way I want)
<script>
// these are for our pictures
var image1 = new Image();
image1.src = "images/bttn_show_analyze.gif";
var image2 = new Image();
image2.src = "images/bttn_hide_analyze.gif";
function change_image(val) {
if (val == 0) {
document["pic"].src = image1.src;
} else {
document["pic"].src = image2.src;
}
}
</script>
(HTML)
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Label01"><!-- return true; -->
<div class="trigger" onClick="showNote('notespan'); change_image(2);"><img
src="images/bttn_show_analyze.gif" alt="Show Analyze Data" width="159" height="17" border="0" name="pic"></div>
</td>
</tr>
<tr>
<td align="right">
<div class="Label01">
<span class="branch" id="notespan">
<TEXTAREA rows="10" cols="100"><%= cqfb.getClaimAnalysis()== null ? " " :
cqfb.getClaimAnalysis()%></TEXTAREA>
</span>
</div>
</td>
</tr>
</table>
I'm trying to do some javascipt that shows/hides a form field by clicking an image. When the user starts off, the image is a "+". When the image is clicked, I want the image to change to a "-", and then go back to a "+" when clicked again. In other words, go back and forth between "+" and "-".
I'm halfway there. The code I created hides and shows the form field, and when the button is clicked initially it swaps the image. Unfortunately, I don't know how to set up a loop so it calls the "+" image the next time. After it swaps once, it's done and won't swap anymore.
Here's my code--this is probably very easy for someone experienced with this. Any help would be appreciated! Thanks!
(this code works-show/hide)
<script LANGUAGE="JavaScript">
<!--
var noteVisible = false;
function showNote(branch) {
showHide(branch);
if (noteVisible)
noteVisible = false;
else {
noteVisible = true;
}
}
//-->
</SCRIPT>
(this code does not swap the images the way I want)
<script>
// these are for our pictures
var image1 = new Image();
image1.src = "images/bttn_show_analyze.gif";
var image2 = new Image();
image2.src = "images/bttn_hide_analyze.gif";
function change_image(val) {
if (val == 0) {
document["pic"].src = image1.src;
} else {
document["pic"].src = image2.src;
}
}
</script>
(HTML)
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="Label01"><!-- return true; -->
<div class="trigger" onClick="showNote('notespan'); change_image(2);"><img
src="images/bttn_show_analyze.gif" alt="Show Analyze Data" width="159" height="17" border="0" name="pic"></div>
</td>
</tr>
<tr>
<td align="right">
<div class="Label01">
<span class="branch" id="notespan">
<TEXTAREA rows="10" cols="100"><%= cqfb.getClaimAnalysis()== null ? " " :
cqfb.getClaimAnalysis()%></TEXTAREA>
</span>
</div>
</td>
</tr>
</table>