Jump to content

enabling and disabling checbox


cyber_ghost

Recommended Posts

is there a way that i can enabled back the check box after disabling it.?

 

code: // javascript

       

function check_me(num)

{

if(num==1) // when mouseover

  document.form1.check_box.disabled=true;

 

if(num==2) // when mouseout

document.form1.check_box.disabled=false;

 

}

 

I already try in textbox field.. and it work correct....

how about checkbox?

 

 

Link to comment
https://forums.phpfreaks.com/topic/78488-enabling-and-disabling-checbox/
Share on other sites

are you wanting something like this?

 

<script language="javascript">

function go(direct)
{
if (direct == "1")
{
  document.form1.check_box.disabled=true;
}
else if (direct == "2")
{
  document.form1.check_box.disabled=false;
}
}

</script>

<form name="form1">
<input type="text" name="num" onmouseover="go(this.value)" onmouseout="go(this.value)" onblur="go(this.value)">
<br><br>
<input type="checkbox" name="check_box" disabled> OK
</form>

 

if your going to do it like this; if I were you, I would go with the onkeyup event, instead of the onmouse events - but that is totally up to you. :)

sorry for this...

 

my point of view is that.. once a user  put the mouse cursor above the checkbox.

 

the checkbox itself turn to disabled.

and once the user remove its cursor above the check box... the check turn to enabled again..

 

here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<script language="javascript">

 

function go(direct)

{

if (direct == "1")

{

document.form1.check_box.disabled=true;

}

else if (direct == "2")

{

document.form1.check_box.disabled=false;

}

}

 

</script>

</head>

 

<body>

 

<form name="form1">

<label>

<input type="checkbox" name="check_box" value="checkbox" onmouseout="go('2')" onmouseover="go('1')" />

move your mouse here</label>

</form>

 

</body>

</html>

 

well, once you disable the checkbox itself; DOM events, that have to be associated with the checkbox to fire javascript, seem not to work. I have never done it like this before; I guess I would have done the opposite of what your wanting to do, so I guess that is why I never had that issue to come up before. I created a worked around; but it in itself is not 100% guaranteed to accomplish what your wanting to do everytime. The code below that I created; is a quick fix to a possibly un-fixable dilemma, for what you are wanting to do.

 

Here It Is:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">

function go(direct)
{
if (direct == "1")
{
  document.form1.check_box.disabled=true;
}
else if (direct == "2")
{
  document.form1.check_box.disabled=false;
}
}

function preventPreCheck()
{
document.form1.check_box.checked=false;
}

</script>
</head>

<body>

<form name="form1">
   <label>
   <span onmouseout="go('2')" style="padding:5px 4px 5px 5px">
   <input type="checkbox" name="check_box" value="checkbox" onmouseover="go('1')"/ onclick="preventPreCheck()" tabindex="-1">
   </span>
   move your mouse here</label>
</form>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.