Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2004, 03:42 PM   PM User | #1
RSH17
New Coder

 
Join Date: Oct 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
RSH17 is an unknown quantity at this point
Button Onclick Event & Switch Statement

Reference: IE 6 & JavaScript

How do I code the onclick event of a button to execute a switch statement?
I wish to use the onclick event of button4 to execute a switch statement to change the value of button1.

<Language=JavaScript>

<INPUT type="button" value="Castings" id=button1 name=button1 >
<INPUT type="button" value="Raw Materials" id=button4 name=button4 onclick = "Raw Material">

<script>

Article = document.MaterialSelector.button4.value

switch (Article) {

case "Raw Material":
document.MaterialSelector.button1.value
break;

default:
break;

}

</script>
RSH17 is offline   Reply With Quote
Old 11-06-2004, 08:17 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
I think this should work:
Code:
<head>
<script language="javascript">
function change()
{
var Article = document.MaterialSelector.button4.value;

	switch(Article)
	{
		case "Raw Materials":
		document.MaterialSelector.button1.value = "Whatever";
		break;
	}

}


</script>
</head>
<body>
<form action="" name="MaterialSelector">
<input type="button" name="button1" value="Castings"><br>
<input type="button" name="button4" value="Raw Materials" onclick="change();"><br>
</form>
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 11-06-2004, 09:11 PM   PM User | #3
RSH17
New Coder

 
Join Date: Oct 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
RSH17 is an unknown quantity at this point
The code above works (Thank you).

After I looked at the above code for awhile, I see that I'm not quite there yet. I shall modify the code so it better represents what I wish to accomplist.

Here is the modified code:

<head>
<script language="javascript">
function change()
{
var Article = document.MaterialSelector.b2.value;

switch(Article)
{
case "Test2":
document.MaterialSelector.b1.value = "Whatever";
break;
}

}


</script>
</head>
<body>
<form action="" name="MaterialSelector">
<input type="button" name="b1" value="Test1" onclick="change();"><br>
<input type="button" name="b2" value="Test2" onclick="change();"><br>
<input type="button" name="b3" value="Test3" onclick="change();"><br>
<input type="button" name="b4" value="Test4" onclick="change();"><br>
</form>

Here is the issue that needs to be resolved. "var Article" is getting its' variable from: b2.value. I need "var Article" to get its' variable from whatever button is clicked on.

How do I code for this to occur?

Last edited by RSH17; 11-07-2004 at 06:30 PM..
RSH17 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:35 AM.


Advertisement
Log in to turn off these ads.