Jump to content

Attn: Need code help


Recommended Posts

Ok I got it to work but I am having an issue now.

When hovering over the text lable it does nothing

When hovering over the image it changes image and brings up the tooltip

How can i make the text do the same

<font class="side" onClick="StopAudio(); stopInterval(); CreateFile('install');">
<i><b>
<script type="text/javascript">
document.write(getText(lblInstall));
</script>
</b></i>
</font>

Do I need to add it into the same line as the image? or have it a seperate line?

I have tryed, and I mean tryed many diffrent thing but cant make it work.

Could you be so kind as to help me once more.

Thank again.

Edited by almulder
Link to comment
Share on other sites


Well I be...

I got it

document.write("<font class=\"side\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"document.continuebutton.src='./themes/" + Theme + "/continuedown.gif';\" onMouseOver=\"document.continuebutton.src='./themes/" + Theme + "/continueover.gif'; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"document.continuebutton.src='./themes/" + Theme + "/continue.gif';\ htm();\" />" + "<i>" + "<b>" + getText(lblInstall) + "</b>" + "</i>" + "</font>");

Just added the new line after the image.

YES YES YES.

Geting Closer....

Link to comment
Share on other sites

Congrats for the fix.

I would have helped you but my local time was 4Am when you posted ... and in the morning (and now it's morning :D) I'm at school :(. I just love the classes that are held in the multimedia lab (I pay no attention to the class :D).

Edited by sadicq
Link to comment
Share on other sites

Thats cool. I made me learn a thing or to trying to make it work. I have a little better understanding of it now, rather than cut and past.

Thanks again

- Albert

Edited by almulder
Link to comment
Share on other sites

I have another code need

How can I do the following

if (document.all["colorcodetextbox"].value == 'a good color code') {

"My code goes here that needs to run if above is true"

}

I need to check a var to see it the value is equal to any good color code like '#000000' - '#FFFFFF'

The var will include the '#' sign

Edit: (I figured out a way around the code I needed below but thank you. I still need the code above though.)

Also I need this: (don't know if this can be done)

MouseMove('Run this function')

MouseButtonHeldDown('Run the function') but still have the first function continue to run when the mouse is move. (Run both functions at the same time.)

and when MouseButtonRelease('Run this function)

Any thoughts.

Thanks again in advance.

Edited by almulder
Link to comment
Share on other sites

This function returns 1 if the value you pass to it is a valid hex color code and 0 if it is not.

function validcolor(colorcode)
{
if (colorcode.substr(0,1) == "#")
{
colorcode = colorcode.substring(1);
if (colorcode.length == 6)
{
var aux = 0;
for (aux = 0; aux < 6; aux++)
{
var character = colorcode.substr(aux,1)
if (character != 0 && character != 1 && character != 2 && character != 3 && character != 4 && character != 5 && character != 6 && character != 7 && character != 8 && character != 9 && character.toLowerCase() != 'a' && character.toLowerCase() != 'b' && character.toLowerCase() != 'c' && character.toLowerCase() != 'd' && character.toLowerCase() != 'e' && character.toLowerCase() != 'f')
{
alert('Your hex code contains a character that is not allowed (only 1..9 and A..F allowed)');
return 0;
}
}
return 1;
}
else
{
alert('Invalid string lenght');
return 0;
}
}
else
{
alert('The string should start with the \"#\" character');
return 0;
}
}

I implemented only 6 chars long hex codes, but I know colors can be defined using 3 chars hex codes ...

Modify it yourself or tell me if there is something you don't like.

Use it like this (in your case):

if (validcolor(document.all["colorcodetextbox"].value)) {
"My code goes here that needs to run if above is true"
}

Offtopic: school .... I just got home ... :wacko:

Edited by sadicq
Link to comment
Share on other sites

Some modifying for the code and it works.

Thank you.

Got anotherone for you.

I have a text box that onBlur it runs a function how can I go about making that textbox the active (focus) box again after it was blur.

I have it check if the info inside is a valid color code. now if it is not I need it to go to another function and make it the active check box again. That way they are forced to enter a correct color code before the can click anything else.

document.all["tttbtcq"].? = ?

what is the correct code

document.all["tttbtcq"].focus();

Just a guess with code I found that did not work.

I need the focus to go back to the "tttbtcq" text box so that as soon as you start typeing is puts that text into that box. Also if possible it would be nice to have it auto select the text that was already inputed into the box. So that it would overight what was already there when a key was pressed.

do I need to worry about removing focus from anythig or will the new focus automaticaly remove the focus from everything else.

Can you help me again?

Edited by almulder
Link to comment
Share on other sites

I've made a sample hta file to demonstrate the use of the code. It supports multiple fields that require validation (see the attacher on init). The validation function has been externalized (and re-written) and the FieldValidator mechanism can operate even with other validators than for color (ColorValidator).

I've had some help with the code from a firend that knows what he's doing :)

<html>
<head>
<script language="JavaScript">
var _validatorArray = new Array();
function ColorValidator(){
this.validate = function(text){
if(text.indexOf("#") != 0 || text.length != 7)
return;
text = text.substring(1).toUpperCase();
while(text.length > 0 && text.charAt(0) >= '0' && text.charAt(0) <= 'F')
text = text.substring(1);
return text.length == 0;
}
}

function FieldValidator(field, validator){
this.field = field;
this.validator = validator;
this.index = -1;

this.isValid= function(){
return this.field.value.length == 0 || this.validator.validate(this.field.value);
}
this.verify = function(){
if(!this.isValid()){
alert("The value you have entered ("+this.field.value+") does not represent a color (in #AAAAAA format) !");
this.field.focus();
this.field.select();
this.field.style.backgroundColor = "#EE1111";
setTimeout(
new this.timer(this.index).time
, 1000
);
}else
if(this.field.value.length > 0){
this.field.style.backgroundColor = "#22EE22";
window.status = this.index;

setTimeout(
new this.timer(this.index).time
, 500
);
}
}
this.timer = function(index){
this.time = function(){
_validatorArray[index].field.style.backgroundColor = "";
}
}
this.focuser = function(index){
this.focus = function(){
try{
for(var i=0; i<_validatorArray.length; i++)
if(i != index && !_validatorArray[i].isValid()){
window.event.cancelBubble = true;
return false;
}
}catch(e){}
return true;
}
}
this.blurer = function(index){
this.blur = function(){
try{
_validatorArray[index].verify();
}catch(e){}
}
}

_validatorArray[(this.index=_validatorArray.length++)] = this;

field.attachEvent(
"onfocus",
new this.focuser(this.index).focus
);


field.attachEvent(
"onblur",
new this.blurer(this.index).blur
);
}
function init(){
new FieldValidator(
document.getElementById("color_code"),
new ColorValidator()
);
new FieldValidator(
document.getElementById("color_code2"),
new ColorValidator()
);
}
</script>
</head>
<body onload="init();">
<input type="text" name="color_code" id="color_code" size="7"/> <br/>
<input type="text" name="color_code2" id="color_code2" size="7"/>
<br/>
Some text to check for validation behaviour
</body>
</html>

Link to comment
Share on other sites

Thank you for the code but kinda got lost trying out that code.

can you or your helper check out the code below and fixit so that it works like the code above.

This is what I have:

Code in the html file

<input name="tttbtc" type="text" class="clTextBox" id="tttbtc" onBlur="validcolor('tttbtcvc')" style="text-align: center; text-transform: uppercase;" value="#333333" size="12" maxlength="7">

<input name="tttbc" type="text" class="clTextBox" onBlur="validcolor('tttbcvc')" id="tttbc" style="text-align: center; text-transform: uppercase;" value="#5498FF" size="12" maxlength="7">

Not sure how to use code above and make it work below

code in a .js file

function validcolor(vcolorcode) 
{
if (vcolorcode=="tttbtcvc") {
vcolorcode=document.all["tttbtc"].value;
checkvalidcolor(vcolorcode);
if (colorreturn == '1') {
PreviewUpdate();
}
else {
alert(" - Invalid Color Code. - ");
// line not working document.all["tttbtcq"].focus();
}
}

if (vcolorcode=="tttbcvc") {
vcolorcode=document.all["tttbc"].value;
checkvalidcolor(vcolorcode);
if (colorreturn == '1') {
PreviewUpdate();
}
else {
alert(" - Invalid Color Code. - ");
// line not working document.all["tttbcq"].focus();
}
}

}

function checkvalidcolor(colorcode)
{
colorreturn='1';
if (colorcode.substr(0,1) == "#")
{
colorcode = colorcode.substring(1);
if (colorcode.length == 6)
{
var aux = 0;
for (aux = 0; aux < 6; aux++)
{
var character = colorcode.substr(aux,1)
if (character != 0 && character != 1 && character != 2 && character != 3 && character != 4 && character != 5 && character != 6 && character != 7 && character != 8 && character != 9 && character.toLowerCase() != 'a' && character.toLowerCase() != 'b' && character.toLowerCase() != 'c' && character.toLowerCase() != 'd' && character.toLowerCase() != 'e' && character.toLowerCase() != 'f')
{
colorreturn='0';
}
}
}
else
{
colorreturn='0';
}
}
else
{
colorreturn='0';
}

}

Sorry to keep bugging you, but you are just such a great help, and I want the theme wizard to work for dummy users also. I am trying to make it as user frendly as possible and check for any possible errors.

Thanks so much for your help.

Link to comment
Share on other sites

Well, the precision of the new function made for checking the colors is not the same with the previous one (it only yells if the color is invalid and it says nothing more. Anyway I see you did not output the details :D ).

But everything is by far better that the previous one.

So here are the modifications you have to make:

The html code must be changed to:

<input name="tttbtc" type="text" class="clTextBox" id="tttbtc" style="text-align: center; text-transform: uppercase;" value="#333333" size="12" maxlength="7"/>
<input name="tttbc" type="text" class="clTextBox" id="tttbc" style="text-align: center; text-transform: uppercase;" value="#5498FF" size="12" maxlength="7">

I removed only the "onblur entry". (i also added a backslash at the end of the <input /> block. XHTML compatible :lol: .

One more thing you have to do inside the html: in the body tag put an onload="init();" statement.

This way,

<body>

Will be

<body onload="init();">

Now, let's move to the js file.

1. Remove all your previous code

2. Paste the following code:

var _validatorArray = new Array();
function ColorValidator()
{
this.validate = function(text)
{
if(text.indexOf("#") != 0 || text.length != 7)
return;
text = text.substring(1).toUpperCase();
while(text.length > 0 && text.charAt(0) >= '0' && text.charAt(0) <= 'F')
text = text.substring(1);
return text.length == 0;
}
}
function FieldValidator(field, validator)
{
this.field = field;
this.validator = validator;
this.index = -1;

this.isValid= function()
{
return this.field.value.length == 0 || this.validator.validate(this.field.value);
}
this.verify = function()
{
if(!this.isValid())
{
alert("The value you have entered ("+this.field.value+") does not represent a color (in #AAAAAA format) !");
this.field.focus();
this.field.select();
this.field.style.backgroundColor = "#EE1111";
setTimeout(new this.timer(this.index).time, 1000);
}
else
if(this.field.value.length > 0)
{
this.field.style.backgroundColor = "#22EE22";
window.status = this.index;

setTimeout(new this.timer(this.index).time, 500);
}
}
this.timer = function(index)
{
this.time = function()
{
_validatorArray[index].field.style.backgroundColor = "";
}
}
this.focuser = function(index)
{
this.focus = function()
{
try
{
for(var i=0; i<_validatorArray.length; i++)
if(i != index && !_validatorArray[i].isValid())
{
window.event.cancelBubble = true;
return false;
}
}
catch(e){}
return true;
}
}
this.blurer = function(index)
{
this.blur = function()
{
try
{
_validatorArray[index].verify();
}
catch(e){}
}
}

_validatorArray[(this.index=_validatorArray.length++)] = this;

field.attachEvent("onfocus", new this.focuser(this.index).focus);
field.attachEvent("onblur", new this.blurer(this.index).blur);
}
function init()
{
new FieldValidator(document.getElementById("tttbtc"), new ColorValidator());
new FieldValidator(document.getElementById("tttbc"), new ColorValidator());
}

in conclusion, when adding a new input, you'll have to do:

1. Make sure the current document's <body> has

onload="init();"

2. Add a line like

<input name="thename" type="text" class="clTextBox" id="thename" style="text-align: center; text-transform: uppercase;" value="#333333" size="12" maxlength="7"/>

3. Edit the init() function in the js file adding a line like this:

new FieldValidator(document.getElementById("thename"), new ColorValidator());

Note: thename is the name of the new introduced input.

Edited by sadicq
Link to comment
Share on other sites

I made every change you did but no luck.

I think it has something to do with the

<body onload="init();">

the htm file that this is added to is just like one of the ones used in the options screen tabs

it has no <body>, so I added <body onload="init();"> at the very top and </body> to the bottom, but no luck.

Thoughts?

Edited by almulder
Link to comment
Share on other sites

Well I'll be I did it. it was the <body onload="init();">

I removed it from the html. and placed inside my .js where it loads the html file. made it the last function to run when rendering the page.

That works.

Thank you again.

Enough messing it up and moving things around I got it. Not as easy as put this here and here but atleast I learned some more.

I'll let you know more if I need it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...