Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

asp / javascript question

  • 24-01-2004 09:54PM
    #1
    Registered Users, Registered Users 2 Posts: 229 ✭✭


    right this one has me confused :) and its gona be hard to explain .... basically im going to be reading a variable from a database threw asp, which is no problem,

    say the variable i want is a colour, so i read it and basically put it into a var below so it will look like this (minus the code to make it easy)

    <%
    colour_of_buttons = "blue"
    %>

    then i use a code like
    <%
    Response.Write "<img border=""0"" src=images/" & colour_of_buttons & "/homeoff.gif>"
    %>

    so basically it will look in a folder called images/blue/homeoff.gif
    and if i put red into colour_of_button then it would look in images/red/homeoff.gif

    so with a click of a button you can change the layout ... all working 100% ... but i want a mouse over to change the image... using the normal MM_swapImage

    i need to change this line to something like

    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/' & colour_of_buttons & '/homeon.gif',1)">

    OR

    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/' + colour_of_buttons +'/homeon.gif',1)">

    or use some sort of brackets or something but i just can't get my head around it at all !!!!

    any advice, i know its simple but just not coming to me
    thanks
    Paul


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,036 Mod ✭✭✭✭Seth Brundle


    You are mixing client side and server side code up. The ASP will generate HTML output and send this to your browser. This may include code (like yours which contains dynamic JavaScript [dynamic in the sense that the ASP chooses the colour]).
    ASP (because it is server side code) cannot respond to mouse events and therefore cannot do this job.

    For it to work you will need to
    a) send the visitors choice to the server where ASP will set a cookie with the colour and this value is called and set into the colour_of_buttons variable.
    or
    b) use JavaScript to set the cookie as in a) but don't use server side code. (http://javascript.internet.com/cookies)


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Originally posted by paulthelegend
    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/' & colour_of_buttons & '/homeon.gif',1)">

    OR

    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/' + colour_of_buttons +'/homeon.gif',1)">

    or use some sort of brackets or something but i just can't get my head around it at all !!!!

    From above, you're just mixing up client vs server side variables... so in JScript ASP your line should read something like ...
    Response.write( "<a href=\"#\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage( 'home', '', 'images/'" + colour_of_buttons + "/homeon.gif', 1 );\">" );
    
    ... and similarly, in VBScript ASP (with which I'm less experienced), the line would be something like ...
    Response.Write "<a href=""#"" onmouseout=""MM_swapImgRestore()"" onmouseover=""MM_swapImage( 'home', '', 'images/'" & colour_of_buttons & "/homeon.gif', 1 );"">"
    

    ... with the main difference being colour_of_buttons is a server side variable, not client side as in your lline.

    That is, if I've interpreted your code and question right.
    HTH
    .cg


  • Registered Users, Registered Users 2 Posts: 229 ✭✭paulthelegend


    Well that would get around the problem, just thought there was a way of doing it without a response.write.

    but thats perfect, gave me another idea to do a loop of reading the image locations so even easier to customise the buttons threw database ... thanks very much (even though you just added about 20 extra hours haha but will be worth it)


  • Registered Users, Registered Users 2 Posts: 3,890 ✭✭✭cgarvey


    Well you can, kinda, its still a server side variable ...
    <a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','images/<%= colour_of_buttons %>/homeon.gif',1)">
    

    .. if that makes it any easier

    .cg


  • Registered Users, Registered Users 2 Posts: 229 ✭✭paulthelegend


    thats exactly what i was looking for, i use that on my tables but just didnt try it there, ill give it a shot later and tell you how i get on, thanks very much


  • Advertisement
Advertisement