...

View Full Version : Is it possible to . . .



Jazzo
04-30-2008, 01:22 AM
Well, first of all, I know hardly any JS but I do have one question. Say I have a variable that is something that is two words, example "Image One: is my variable. Is there a way to turn that variable into "ImageOne?" To just remove the space? Thanks for the help.

oesxyl
04-30-2008, 01:31 AM
Well, first of all, I know hardly any JS but I do have one question. Say I have a variable that is something that is two words, example "Image One: is my variable. Is there a way to turn that variable into "ImageOne?" To just remove the space? Thanks for the help.

Just to make me clear something: a variable name can't have two words, so I assume that you are talking about a variable value.


var s = "Image One";
s.replace(/\s+/g,'');


regards

Jazzo
04-30-2008, 01:38 AM
Yes, I do mean a variable value :D (silly me) and thank you!!!

Jazzo
04-30-2008, 01:44 AM
Hmm, it doesn't seem to be working. Here's more of my source code:


if(document.getElementById(imagename) !== null){
var image = "#" + imagename;
location.href = image;


Where do you think I should put it?

oesxyl
04-30-2008, 02:02 AM
Hmm, it doesn't seem to be working. Here's more of my source code:


if(document.getElementById(imagename) !== null){
var image = "#" + imagename;
location.href = image;


1.) here imagename is a variable and his value must be the id of a html element, something like:


<img id="vimag" ... />

so imagename = 'vimag'
2.) image must be anchor because you try to use location to go there and his value is #vimage, so you must have in your html code something like:


<a name="vimag"....

3.) this do nothing if you don't use a event like onclick or something
Maybe I could help if you say what you want to achive.



Where do you think I should put it?
in the head section of the (x)html page or in the body at the bottom of the section:


<script type="text/javascript">
// your code here
</script>

if you want to put into an external file, say 'jscode.js' you can put in the head section:


<script type="text/javascript" src="jscode.js"></script>


regards

Jazzo
04-30-2008, 02:23 AM
OK, well, what I have is a search function where you enter the name of the image (which is the ID div element that contains the image) and it takes you to there. The only problem is that for it to validate, the ID cannot contain spaces. What I want to do is make the IDs of the div elements the imagename without spaces and I want a script (that I already have in place) to first remove the spaces, and then go to that ID. (And I already have the else statement) so if you could give me just the "if" part, that would be great. You get it?

oesxyl
04-30-2008, 02:47 AM
OK, well, what I have is a search function where you enter the name of the image (which is the ID div element that contains the image) and it takes you to there. The only problem is that for it to validate, the ID cannot contain spaces. What I want to do is make the IDs of the div elements the imagename without spaces and I want a script (that I already have in place) to first remove the spaces, and then go to that ID. (And I already have the else statement) so if you could give me just the "if" part, that would be great. You get it?
this don't work:


<div id="ImageOne"....

this work:


<a name="ImageOne">...

with this:


imagename.replace(/\s+/g,'');
if(document.getElementById(imagename) != null){
location.hash = imagename;
}

It's not tested and I assume that imagename contain the value "ImageName" and the click on something fill imagename with what is in the search box.
You can check imagename value using a alert(imagename) before imagename.replace

regard



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum