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
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. :)

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.