ja***********@gmail.com wrote:
So I liked both answers, but the second one, although probably more
"right", doesnt seem to be working for me isnce im such an amateur...
But the idea of simply adding making a variable that says "dont
rollover if this one has been clicked" sounds great! Its easy for me to
understand, and smells like it will work... but hasnt yet.
here is what im doing:
// Making these global variables
var model;
var theDiv;
// Storing the selected phone into a hidden field for a form
function selectPhone(model) {
document.getElementById('myPhone').value=model;
}
// Making the div that is provided in this paramater have a border
function rollBorder(theDiv) {
document.getElementById(theDiv).style.border='2px solid #ff9900';
document.getElementById(theDiv).style.padding='0px ';
}
// Heres the problem, i want the rolloff only to work if theDiv has not
been clicked
function rollNoBorder(theDiv) {
if (theDiv != model)
{
document.getElementById(theDiv).style.border='0px solid #ff9900';
document.getElementById(theDiv).style.padding='2px ';
}
}
and then here is the div itself:
<div id="box1" onClick="selectPhone('A1000');"
onMouseOver="rollBorder('box1');"
onmouseout="rollNoBorder('box1');">PHONE</div>
Any ideas??
Here's another approach, a slight variant to what you already have. I
think it's somewhat cleaner.
Your CSS:
..borderon
{
border: 2px solid #F90;
padding: 0px;
}
..borderoff
{
border: 0px solid #F90;
padding: 2px;
}
Your JS:
//global variable to keep track of the clicked div
var clicked_div = null;
function myClick(div_elem, model)
{
if(clicked_div)
{
//turn 'off' old div
clicked_div.className = "borderoff";
//replace old div with new clicked div
clicked_div = div_elem;
//turn the new div 'on'
clicked_div.className = "borderon";
}
}
function myMOver(div_elem)
{
div_elem.className = "borderon";
}
function myMOut(div_elem)
{
div_elem.className = "borderoff";
//whatever div element you mouse out of, turn the clicked element on
anyway
if(clicked_div)
{
clicked_div.className = "borderon";
}
}
Your HTML:
<div onclick = "myClick(this, 'A1000');"
onmouseover = "myMOver(this);"
onmouseout = "myMOut(this);">text</div>
One of the benefits of this way is that you can dynamically assign all
your necessary divs the onmouseover and onmouseout event handlers
through javascript instead of handcoding them.