eevan79 Posted October 2, 2010 Share Posted October 2, 2010 This code only works in firefox <a onMouseout='hidetooltip()' onMouseover='tooltip(\"<img src=img/heroes/$hero.gif\")' href='hero.php?hero=$hero'>Text</a> Btw, I use this in echo (php). How to get quotes (triple) on <img src= ? I also have tried <img src='img/heroes/$hero.gif' But only works on FireFox Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/ Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 ok so a lesson on quotes...one of my favorites....first off in any case that you can use single quotes use those as php process them faster than double quotes. here are some examples: //will not work - variables need to be in double quotes or outside of quotes$string = 'Some String $test';//correct way for example above$string = 'Some String'.$test;//another way for example above$string = "Some String $test";//yet another way for example above - method I use if I have to so that the variables dont get confused with other characters$string = "Some String {$test}";//using double quotes inside of single quotes$string = 'Some String "with a quote"';//using double quotes and single quotes inside of string - whichever quotes you start with can be used inside of itself but must be escaped using a \ (backslash) character$string = 'Some String "with some quote\'s"';//Yours fixed$string = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\'<img src=img/heroes/'.$hero.'.gif\');" href="hero.php?hero='.$hero.'">Text</a>'; Hopefully that helps. If you have any questions feel free to ask. Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118213 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 Thats exactly how I wrote code above...And as I said its not working. I echo your code $string = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\'<img src=img/heroes/'.$hero.'.gif\');" href="hero.php?hero='.$hero.'">Text</a>'; echo $string; and get this And here is working example: $img = "<img src=img/heroes/$hero.gif>"; $hero = "<a onMouseout='hidetooltip()' onMouseover='tooltip(\"".$img."\",130)' href='hero.php?hero=$hero'><img alt='' width='28px' src='./img/heroes/$hero.gif' border=0></a>";} Dont need for lesson this time, please...just working example You see why your code is not valid. You open single quote for tooltip and then close it before you close tooltip () . onMouseover="tooltip(\'<img src=img/heroes/'.$hero.'.gif\'); Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118225 Share on other sites More sharing options...
joel24 Posted October 2, 2010 Share Posted October 2, 2010 you can't use single quotes inside a string encased in single quote unless you escape the character with a backslash or use double quotes instead. at the start and end of the <img> tag you have single quotes. and also you have a backslash at the end of the tooltip image tag rather than a > $string = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\"<img src=img/heroes/'.$hero.'.gif>");" href="hero.php?hero='.$hero.'">Text</a>'; echo $string; IMO it would be much easier to write the string in double quotes $string = "<a onMouseout='hidetooltip();' onMouseover='tooltip(\'<img src=img/heroes/$hero.gif>');' href='hero.php?hero=$hero>Text</a>"; echo $string; have a look at the HTML source of the php page and you could easily rectify this issue. Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118227 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 You cant use OnMouseOver atribute with single quote and same single quote for function tooltip if you have another quotes inside tooltip function. So we have opening quotes for string, then onmouseover and tooltip. This need to be escaped multiple not just with an \, so thats why is my code above valid. Your code give me similiar results. Also you didnt escape quote at end of tooltip $hero.gif>');' Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118228 Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 I find it funny that you ask for help, I give you help, and then you try to tell me how to write code. I also find it funny that I copied exactly what I posted to you and put it on my dev server and it works just fine so there must be something that you are not sharing with us. You see why your code is not valid. You open single quote for tooltip and then close it before you close tooltip () . onMouseover="tooltip(\'<img src=img/heroes/'.$hero.'.gif\'); My code is completely valid. If you notice the single quote is escaped using the \ so it does not end the single quotes. If you were referring the the quote before $hero that just exits the current string literal and puts out the variable and the on after it start the string literal back. Maybe you should post your full code or try mine again because it works perfect on my machine. Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118312 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 Ok...thank you for your time. Just note that code is working for you, not for me. It depence what is your tooltip function. And there is no additional code that I'm not sharing or else. HTML is valid. Your forgot say about quotes for ...HREF=" and string $string="<a... $string = "<a href=' I understand why its not valid your example. Because you open single quote for mouseover and then for tootip. Try it in HTML, and you will see this is not valid. "<a onmouseover='tooltip('some_text, or whatever')'..." Yes, it's escaped but in html there's double opening single quotes. We have this quote "structure" (blue are double, red are single and orange is single inside red quotes): " ' ' ' ' " It's not Pyhton that have triple quotes. You can see almost same problem here . Anyway, thank for your time, I appreciate it. (marked as solved.) Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118329 Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 I understand why its not valid your example. Because you open single quote for mouseover and then for tootip. Try it in HTML, and you will see this is not valid. "<a onmouseover='tooltip('some_text, or whatever')'..." Shows you werent using my code lol. My mouseover was encapsed by double quotes. Quoted from my previous post //Yours fixed $string = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\'<img src=img/heroes/'.$hero.'.gif\');" href="hero.php?hero='.$hero.'">Text</a>'; Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118336 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 OMG, you are right. I made big mistake, sorry. I put your code instead of my code, but there one quote left from my previous code. So thats why we can see that layout. Anyways here is your code (I have added one more string, but basically its yours) $hero = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\''.$heroname.'<br><img src=img/heroes/'.$hero.'.gif\');" href="hero.php?hero='.$hero.'"><img alt="" width="28px" src="./img/heroes/'.$hero.'.gif" border=0></a>'; Apologies for the misunderstanding...what else can I say EDIT: Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118347 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 bah...now we are at start with this code. It's working only in FFox, cause there is no quotes for <img src inside tooltip function in your code... Still my old code is working... Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118350 Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 sorry I didnt notice that you didnt have quotes around the img tag. I never pass stuff through a function like that. Why dont you just send the hero name and the hero image path and then in the tooltip function have it so that it will just put the image path inside of the img tag inside of that function. here is an example: PHP CODE $hero = '<a onMouseout="hidetooltip();" onMouseover="tooltip(\''.$heroname.'\',\'img/heroes/'.$hero.'\.gif');" href="hero.php?hero='.$hero.'"><img alt="" width="28px" src="./img/heroes/'.$hero.'.gif" border=0></a>'; JAVASCRIPT function tooltip(hero_name,hero){ var img_path = '<img src="'+hero+'" />'; var data = hero_name+'<br />'+img_path; alert(data); } Wasnt tested but hopefully you get the idea of what I was getting at. Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118423 Share on other sites More sharing options...
eevan79 Posted October 2, 2010 Author Share Posted October 2, 2010 Yeah...that was my question about (look at first post) . I know that I can solve it with adding additional vars into javascript, but my script is a bit complicated then that. var offsetfromcursorX=12 //x offset of tooltip var offsetfromcursorY=10 //y offset of tooltip var offsetdivfrompointerX=10 //x offset of tooltip DIV relative to pointer image var offsetdivfrompointerY=14 //y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1). document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV document.write('<img id="dhtmlpointer" src="img/arrow.gif">') //write out pointer image var ie=document.all var ns6=document.getElementById && !document.all var enabletip=false if (ie||ns6) var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "" function ietruebody(){ return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body } function tooltip(thetext, thewidth, thecolor){ if (ns6||ie){ if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor tipobj.innerHTML=thetext enabletip=true return false } } function positiontip(e){ if (enabletip){ var nondefaultpos=false var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft; var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop; //Find out how close the mouse is to the corner of the window var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20 var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20 var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000 //if the horizontal distance isn't enough to accomodate the width of the context menu if (rightedge<tipobj.offsetWidth){ //move the horizontal position of the menu to the left by it's width tipobj.style.left=curX-tipobj.offsetWidth+"px" nondefaultpos=true } else if (curX<leftedge) tipobj.style.left="5px" else{ //position the horizontal position of the menu where the mouse is positioned tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px" pointerobj.style.left=curX+offsetfromcursorX+"px" } //same concept with the vertical position if (bottomedge<tipobj.offsetHeight){ tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px" nondefaultpos=true } else{ tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px" pointerobj.style.top=curY+offsetfromcursorY+"px" } tipobj.style.visibility="visible" if (!nondefaultpos) pointerobj.style.visibility="visible" else pointerobj.style.visibility="hidden" } } function hidetooltip(){ if (ns6||ie){ enabletip=false tipobj.style.visibility="hidden" pointerobj.style.visibility="hidden" tipobj.style.left="-1000px" tipobj.style.backgroundColor='' tipobj.style.width='' } } document.onmousemove=positiontip I'll probably switch this script to JQuery... Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118426 Share on other sites More sharing options...
joel24 Posted October 2, 2010 Share Posted October 2, 2010 I'll probably switch this script to JQuery... I would too Link to comment https://forums.phpfreaks.com/topic/214963-quotes-inside-double-and-single-quotes-triple-quotes/#findComment-1118441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.