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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing button value 1

Status
Not open for further replies.

ksbrace

Programmer
May 13, 2000
501
US
Hello, I have a function to show/hide a layer. I would like to be able to change the text value of the button to coincide with the appropriate value. For instance, they click on "Show" and it shows the layer. Now, I would like the button value to say "Hide". thanks in advance!
 
could you just add into the function something like:

document.all.FormName.ButtonName.value="Show";

vice versa:

document.all.FormName.ButtonName.value="Hide";
 
ok, that was what I was looking for. Now, I have 3 buttons that need to implement this functionality. I would like to be able to just pass the id of the button have the function change the value, but it doesn't seem to be working. Any help would be greatly appreciated. Thanks in advance!
Code:
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
			<!--
			var visibility;
			var switchState;
			//change varible status
			function switchState(switchState,button) {
				if (switchState == 'visible') {
					switchState = 'hidden';
					document.all.Form1.button.value=&quot;Show Description&quot;;
				}
				else {
					switchState = 'visible';
					document.all.Form1.button.value=&quot;Hide Description&quot;;
				}
				return switchState
			}
			
			//check which browser and run appropriate code
			function opposite(layer,button) {
				//Run if IE Browser
				if (document.all) {
					visibleState = eval(&quot;document.all.&quot; + layer + &quot;.style.visibility&quot;);
					eval(&quot;document.all.&quot; + layer + &quot;.style.visibility = switchState(visibleState,button)&quot;);
			
				}
				//Run if Netscape Browser
				if (document.layers) {
					visibleState = document.layers[layer].visibility;
										eval(&quot;document.layers.&quot; + layer + &quot;.visibility = switchState(visibleState,button)&quot;);
				}
			}
call to function
Code:
<input type=&quot;button&quot; id=&quot;divButton&quot; onClick=&quot;opposite('demodiv');&quot; value=&quot;Show Description&quot;>
 
Sorry, the call to the function is:
Code:
<input type=&quot;button&quot; id=&quot;divButton&quot; onClick=&quot;opposite('demodiv','divButton');&quot; value=&quot;Show Description&quot;>
 
Using variables may change this:

document.all.Form1.button.value=&quot;Show Description&quot;;

This may be looking for a button named &quot;button&quot;

hmmm let me think about it...
 
TheConeHead,
I ended up finding a script and modifying it. Thanks for your help. Here is the function:
Code:
//changing the buttons values
			function changeName(theElement)
			{
				var oldName = theElement.value;
				if(oldName == &quot;Show Description&quot;) {
				theElement.value = &quot;Hide Description&quot;;
				}
				else if(oldName == &quot;Hide Description&quot;){
					theElement.value = &quot;Show Description&quot;;
				}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top