Jump to content

Code Help Please


Recommended Posts

hopeing you guys can help me out again

Here is the current code (working)

document.write("<img src=\"./themes/" + Theme + "/installbutton.gif\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"document.continuebutton.src='./themes/" + Theme + "/installdown.gif';\" onMouseOver=\"document.continuebutton.src='./themes/" + Theme + "/installover.gif'; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"document.continuebutton.src='./themes/" + Theme + "/installbutton.gif';\ htm();\" />");

This is what I am hoping to change it to (not working)

document.write("<img src=\"InstallButtonPic;\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"InstallButtonDownPic;\" onMouseOver=\"InstallButtonOverPic; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"InstallButtonPic;\ htm();\" />");

I am trying to have it show a pic, but load it from a var instead of pointing to the file directly

The code i am trying to use to for the value of the var = to the file location (not working)

InstallButtonDownPic="document.continuebutton.src='./themes/" + Theme + "/installdown.gif' ";
InstallButtonOverPic="document.continuebutton.src='./themes/" + Theme + "/installover.gif '';
InstallButtonPic="document.continuebutton.src='./themes/" + Theme + "/installbutton.gif' ";

But it is not working can you help please, I have tried several dozen or so things but with no luck.

Thank you.

-Albert

Edited by almulder
Link to comment
Share on other sites


function InstallButtonDownPic()
{
document.getElementById("continuebutton").src="./themes/" + Theme + "/installdown.gif";
}
function InstallButtonOverPic()
{
document.getElementById("continuebutton").src="./themes/" + Theme + "/installover.gif";
}
function InstallButtonPic()
{
document.getElementById("continuebutton").src="./themes/" + Theme + "/installbutton.gif";
}

document.write('<img src="./themes/' + Theme + '/installbutton.gif" align="absbottom" class="mainbtn" border="0" name="continuebutton" id="continuebutton" onClick="StopAudio(); stopInterval(); CreateFile(\'install\');" onMouseDown="InstallButtonDownPic();" onMouseOver="InstallButtonOverPic(); stm(getText(ttInstall),Style[0]);" onMouseOut="InstallButtonPic(); htm();" />');

Edited by sadicq
Link to comment
Share on other sites

thats kinda what I had at one point but what i need is the ability to have a var there that I can change when needed. each pic in the line (all 4) need them to become a var so I can change it as needed. if that means having it run to a function that is ok, but need to be able to make the var any pic I want.

I am currently using if statments to have it select 1 out of 3 possible pics for each and every pic with in the wpi.htm file, but with so many if statments it is causing weird things. When moving the mouse over one button and the over another button back and forth rapidly the pic will dissapear and not come back until the screen is refreshed. So I need to get the if statments out and make only one set that runs at the begining and just changes a var.

Here is an example of what I currently have.

This is with in the WPI.htm file (I use somthing just like it for each button.

<!-- The Install button. -->
<div id="InstallButton">
<script language="javascript">
LoadInstallpic();
</script>
<br>
</div>

This is with in a .js file

function LoadInstallpic() {
if (ButtonType =='p') {
document.write("<img src=\"./themes/" + Theme + "/installbutton.gif\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"document.continuebutton.src='./themes/" + Theme + "/installdown.gif';\" onMouseOver=\"document.continuebutton.src='./themes/" + Theme + "/installover.gif'; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"document.continuebutton.src='./themes/" + Theme + "/installbutton.gif';\ htm();\" />");
}
if (ButtonType =='pt'){
document.write("<img src=\"./themes/" + Theme + "/installbutton.gif\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"document.continuebutton.src='./themes/" + Theme + "/installdown.gif';\" onMouseOver=\"document.continuebutton.src='./themes/" + Theme + "/installover.gif'; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"document.continuebutton.src='./themes/" + Theme + "/installbutton.gif';\ htm();\" />");
document.write("<font class=\"side\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"document.continuebutton.src='./themes/" + Theme + "/installdown.gif';\" onMouseOver=\"document.continuebutton.src='./themes/" + Theme + "/installover.gif'; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"document.continuebutton.src='./themes/" + Theme + "/installbutton.gif';\ htm();\" />" + "<i>" + "<b>" + getText(lblInstall) + "</b>" + "</i>" + "</font>");
}
if (ButtonType =='t'){
document.write("<font class=\"side\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseOver=\"stm(getText(ttInstall),Style[0]);\" onMouseOut=\"htm();\" />" + "<i>" + "<b>" + getText(lblInstall) + "</b>" + "</i>" + "</font>");
}
}

It seems that each time I move the mouse over a button it runs down the whole if list. and that is what is causing my problem.

So I am trying to have the WPI.htm run a Loadpicvar(); function at load time with the Loadpicvar(); function haveing something like this

function Loadpicvar() {

if (ButtonType =='p') {
InstallButtonDownPic="./themes/" + Theme + "/installdown.gif";
InstallButtonOverPic="./themes/" + Theme + "/installover.gif";
InstallButtonPic="./themes/" + Theme + "/installbutton.gif";
ttInstall='';




}

if (ButtonType =='pt') {
InstallButtonDownPic="./themes/" + Theme + "/installdown.gif";
InstallButtonOverPic="./themes/" + Theme + "/installover.gif";
InstallButtonPic="./themes/" + Theme + "/installbutton.gif";




}

if (ButtonType =='t') {
InstallButtonDownPic="./Common/spacer.gif";
InstallButtonOverPic="./Common/spacer.gif";
InstallButtonPic="./Common/spacer.gif";





}

And then having the WHI.HTM having something like this

<div id="InstallButton">
<script language="javascript">
document.write("<img src=\"InstallButtonPic;\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"InstallButtonDownPic;\" onMouseOver=\"InstallButtonOverPic; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"InstallButtonPic;\ htm();\" />");
</script>
<br>
</div>

Hope that is a little more detailed for you. and that you now understand what it is I am looking to do.

Again Thanks for your help

-Albert

Edited by almulder
Link to comment
Share on other sites

I'm pretty sure that your problem of the pic disapearing briefly is not related to your code, but to how mshta handle the events.

You may have better results with the following code:

<div id="InstallButton">
<script language="javascript">
InstallButtonDownPic="./themes/" + Theme + "/installdown.gif";
InstallButtonOverPic="./themes/" + Theme + "/installover.gif";
InstallButtonPic="./themes/" + Theme + "/installbutton.gif";
spacer="./Common/spacer.gif";
//debug var ButtonType ='pt';

document.write('<img src="'+(ButtonType == 't' ? spacer : InstallButtonPic)+'" align="absbottom" class="mainbtn" border="0" name="continuebutton" id="continuebutton" onClick="StopAudio(); stopInterval(); CreateFile(\'install\');" '+(ButtonType == 't' ? '' : 'onMouseDown="this.src=InstallButtonDownPic;" ')+'onMouseOver="'+(ButtonType == 't' ? '' : 'this.src=InstallButtonOverPic; ')+(ButtonType == 'p' ? '' : 'stm(getText(ttInstall),Style[0]);')+'" onMouseOut="'+(ButtonType == 't' ? '' : 'this.src=InstallButtonPic; ')+(ButtonType == 'p' ? '' : 'htm();')+'" />');
</script>
<br>
</div>

This doesn't require the Loadpicvar() function. And it's tested working.

Basically, it writes the minimal quantity of needed code to the document, depending on the 'ButtonType' value. But I don't guaranty that the problem will completely disappear.

[EDIT] Although it should be okay, beware of spaces when copy/pasting the above code: the whole document.write... statement is on 1 line. Double check your copy of the code before using it.

Edited by Djé
Link to comment
Share on other sites

Although that code might work I prefer to have the var defiended with in a function with in a seperate .js I have other things using the vars.

I found out why my var were not working and how have them reciving the info, but if you could help me get my code working now.

document.write("<img src=\"InstallButtonPic;\" align=\"absbottom\" class=\"mainbtn\" border=\"0\" name=\"continuebutton\" id=\"continuebutton\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"InstallButtonDownPic;\" onMouseOver=\"InstallButtonOverPic; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"InstallButtonPic;\ htm();\" />");

Thanks

-Albert

Edited by almulder
Link to comment
Share on other sites

I hope I understood you right this time.

InstallButtonDownPic = 'continuebutton.src=\'./themes/' + Theme + '/installdown.gif\';';
InstallButtonOverPic = 'continuebutton.src=\'./themes/' + Theme + '/installover.gif\';';
InstallButtonPic = 'continuebutton.src=\'./themes/' + Theme + '/installbutton.gif\';';

And

document.write('<img src="" onError="' + InstallButtonPic + '" align="absbottom" class="mainbtn" border="0" name="continuebutton" id="continuebutton" onClick="StopAudio(); stopInterval(); CreateFile(\'install\');" onMouseDown="' + InstallButtonDownPic + '" onMouseOver="' + InstallButtonOverPic + ' stm(getText(ttInstall),Style[0]);" onMouseOut="' + InstallButtonPic + 'htm();" />');

Edit: small code enhancement.

Edited by sadicq
Link to comment
Share on other sites

Works, Thanks man. I just can't seem to figure out the codes of why use ' and other times use " and also the use of \

Can you point me in the right direction on this?

Or elaborat on it some.

Thank you so much.

Link to comment
Share on other sites

Although that code might work I prefer to have the var defiended with in a function with in a seperate .js I have other things using the vars.

??? :blink: But you can have the var definitions wherever you want!

The 'Theme', 'ttInstall' or 'Style' variables you're using are already defined elsewhere. So why not these as well?

I've just put it there for the sake of clarity.

Beside, this code also handle the 3 possible states: p, pt & t you want to deal with.

Now if you want the vars to have different values depending on 'ButtonType', just do this:

InstallButtonDownPic=(ButtonType == 't' ? "./Common/spacer.gif" : "./themes/" + Theme + "/installdown.gif");
InstallButtonOverPic=(ButtonType == 't' ? "./Common/spacer.gif" : "./themes/" + Theme + "/installover.gif");
InstallButtonPic=(ButtonType == 't' ? "./Common/spacer.gif" : "./themes/" + Theme + "/installbutton.gif");
ttInstall=(ButtonType == 'p' ? '': ttInstall);

No need for all the 'if's.

And then

<div id="InstallButton">
<script language="javascript">
document.write('<img src="'+InstallButtonPic+'" align="absbottom" class="mainbtn" border="0" name="continuebutton" id="continuebutton" onClick="StopAudio(); stopInterval(); CreateFile(\'install\');" onMouseDown="this.src=InstallButtonDownPic;" onMouseOver="this.src=InstallButtonOverPic; stm(getText(ttInstall),Style[0]);" onMouseOut="this.src=InstallButtonPic; htm();" />');
</script>
<br>
</div>

BUT then, in the 'p' or in the 't' cases, you'll have useless events which may be the root of you problems with the img disapearing...

Link to comment
Share on other sites

Well in js a string can be enclosed in 's or in "s. It doesn't matter.

If you have the string a'b and use "s you'll get "a'b"

But if you have a'b and you use 's you'd get 'a'b'. So how does js know whether the second one is the end of the string or just a ' inside the string? It doesn't. you'll have to specify this by escaping the char with a backslash. So the correct code is 'a\'b'.

Now, if your string has lots of double quotes in it, you'll have to escape each one of them. Or to simply enclose the string into simple quotes. This why I modified your code replacing "s with 's.

I personally use notepad2 and it helps me a lot with syntax highlighting ... You don't need to use a special editor, but that way you see if you have forgot to escape some special chars.

If you have any other question or my explanation was not good enough, post back.

Edited by sadicq
Link to comment
Share on other sites

Sorry sadicq I have the need for your help with one more that I completely missed.

document.write("<font class=\"side\" onClick=\"StopAudio(); stopInterval(); CreateFile('install');\" onMouseDown=\"InstallButtonDownPic;\" onMouseOver=\"InstallButtonOverPic; stm(getText(ttInstall),Style[0]);\" onMouseOut=\"InstallButtonPic;\ htm();\" />" + "<i>" + "<b>" + getText(lblInstall) + "</b>" + "</i>" + "</font>");

So if you could make this one also work, tha would be great. If all goes well I might have this section of my project done (Finally a month and a half later)

Thank You

-Albert

Update: Just noticeed your post must have been doing it the same time I was. Thanks for the explination. I will use that info. But if you could (Since you are much quicker and know what you are doing could you still edit the above code for me? Thanks)

Edited by almulder
Link to comment
Share on other sites

document.write('<font class="side" onClick="StopAudio(); stopInterval(); CreateFile(\'install\');" onMouseDown="' + InstallButtonDownPic + '" onMouseOver="' + InstallButtonOverPic + ' stm(getText(ttInstall),Style[0]);" onMouseOut="' + InstallButtonPic + ' htm();" /><i><b>' + getText(lblInstall) + '</b></i></font>');

I see a backslash before the htm() function call

\ htm()

Is that a typo?

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...