Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

asp / javascript question

Options
  • 24-01-2004 9:54pm
    #1
    Registered Users 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 Posts: 39,950 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 Posts: 3,886 ✭✭✭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 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 Posts: 3,886 ✭✭✭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 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