Jump to content

Ajax And Some Help Aswell


ckrudelux

Recommended Posts

First off my issue I have code that works in IE but not in FireFox, Opera and Chrome.

function bbcode(bbtag){	if(document.getElementById(bbtag).style.backgroundColor == '#000'){			document.getElementById(bbtag).style.backgroundColor = '#0f0';		}else{			document.getElementById(bbtag).style.backgroundColor = '#000';		}	}

Just thought this would be easy thing to do, okay this just some testing I'm doing for the bigger thing I building so actually I'm going to change background image but still having problems with changing style with javascript.Second thing, I've been thinking about ajax, what is it? I know it's a way to use javascript. But what do I add to the javascript so it becomes ajax?

Link to comment
Share on other sites

If your backgroundColor starts off #000 because of a CSS declaration, then JavaScript thinks its value is an empty string. It only has a value in JavaScript when you set it in JavaScript. If this describes your situation, then this small change should help:

var el = document.getElementById(bbtag);if(el.style.backgroundColor == '#000' || el.style.backgroundColor == ""){

The easiest way to debug a thing like that would have been to alert the backgroundColor at the start of your bbcode() function.---AJAX is a way of communicating with your server in the background, without posting any forms, and without requiring a page to download or refresh.The server itself has no idea that you are communicating through AJAX. It receives an ordinary POST or GET request and returns whatever data you've programmed it to return.On the browser side, it all begins with the XMLHttpObject, which is hard to type, so I call it the AJAX object. An AJAX object has methods for setting request headers and some other things, a property where you assign the data you're sending to your server, and of course a method for actually sending it.Another of its properties gets assigned a callback function. This function mostly just sits there doing nothing until AJAX receives a response from the server. When that has happened, the callback function gets triggered, and you can find the response in one of AJAX's properties. Depending on your application, the response can be a plain text string, but it can also be a string formatted as XML, and AJAX will recognize it as an XML object. That means you don't need to parse it before accessing it with DOM techniques.

Link to comment
Share on other sites

Still don't work.. maybe it's couse I use divs as buttons?

<html>	<head>	<script type="text/javascript">		function bbcode(bbtag){			var el = document.getElementById(bbtag);			if(el.style.backgroundColor == '#000' || el.style.backgroundColor == ""){				el.style.backgroundColor = '#0f0';			}else{				el.style.backgroundColor = '#000';			}		}	</script>	<head>	<body>			<div style="width: 600px;">				<div style="float: left; width: 200px;">					<div id="b" onclick="bbcode('b')" style="float: left; width: 20px; height: 20px; background: #000;"></div>					<div id="h" onclick="bbcode('h')" style="float: left; width: 20px; height: 20px; background: #000;"></div>					<div id="u" onclick="bbcode('u')" style="float: left; width: 20px; height: 20px; background: #000;"></div>					<div id="i" onclick="bbcode('i')" style="float: left; width: 20px; height: 20px; background: #000;"></div>				</div>				<div style="float: left; width: 400px;">					<textarea id="my_textarea" style="float: left; width: 400px;"></textarea>				</div>			</div>	</body></html>

Link to comment
Share on other sites

Hmm. When I alert that in FF, I get this: rgb(0, 0, 0)I forgot that can happen. I've also had weird stuff happen in the past where you set properties in shorthand (background: #000), but then try to access one property like backgroundColor.Stuff to think about!

Link to comment
Share on other sites

Hmm. When I alert that in FF, I get this: rgb(0, 0, 0)I forgot that can happen. I've also had weird stuff happen in the past where you set properties in shorthand (background: #000), but then try to access one property like backgroundColor.Stuff to think about!
Okay so I get an empty respons, still the same message for the alert but the color change but not back again then I click on it one more time. Do I take away the if nothing do first step statement nothing works so whats why I know it's empty.Okay by some weird reason I got a new message maybe the browser stored something :)Still the statement don't work but I get the number so I don't know why couse now it gets the right things.Okay everything works know :)
Link to comment
Share on other sites

Okay new problem... :)

function(bbtag, formName, textName){document.formName.textName.value += "["+bbtag+"]";}

This isn't working :) but it works if I write the value of formName and textName my self like this:

function(bbtag){document.FPreplay.text.value += "["+bbtag+"]";}

Link to comment
Share on other sites

That's because it's trying to find document.formName, literally. You have to search for the tag with that name (or just use ID).

Link to comment
Share on other sites

That's because it's trying to find document.formName, literally. You have to search for the tag with that name (or just use ID).
Thanks didn't think of using a id number before :) Thanks for the help.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...