Jump to content

Javascript Buttons


d22552000

Recommended Posts

function buttoncase(id) {
var i = document.getElementById(id);
var a = document.getElementById("is" + id);

if (a = true) {
	i.class = "buttons";
	a.value = "false";      //PICK ME, I'M LINE 7
} else {
	i.class = "buttons2";
	a.value = "true";
}
}

 

I have made hidden form tags for all my isname fields, and yet I get:  "Line 7, character 5, expected identifier"

Link to comment
https://forums.phpfreaks.com/topic/95349-javascript-buttons/
Share on other sites

You have a few issues with your code

 

i.class = "buttons";

 

To assign a class name to an object, you should use className, so your code will be

 

i.className = "buttons";

 

 

if (a = true)

 

First a is an object (not a boolean) assuming it's an input field you can access it's value using the value attribute

 

a.value

 

for comparson use the douple == signs otherwise the statment will always be true since it's only assigning true to a

 

Finally, all input values are strings so to compare it to a boolean will return false. Your if statment should look like this

 

if (a.value == "true") {

Link to comment
https://forums.phpfreaks.com/topic/95349-javascript-buttons/#findComment-490586
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.