Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2003, 02:11 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default Checkbox with link

hi there again...
i have pick this code around the web by clicking the lick beside the checkbox it will be checked.
Code:
Javascript:
<!-- Begin: checkBox setOn when textclick
function changeBox(cbox) {
box = eval(cbox);
box.checked = !box.checked;
}//  End -->
HTML:
<form name="ccForm">
<input type="checkbox" name="ccNominatedBy">
<a class="chekbox" href="#" onClick="changeBox('document.ccForm.ccNominatedBy');return false">Checkit!</a><br>
<input type="text" name="ccNominaterLN">
<input type="text" name="ccNominaterFN">
<input type="text" name="ccNominaterMN">
</form>
what i want to do is.. at the same time; by clicking the link to check the box the 3 textbox also will turn disabled. how this will accomplished.. help code from anyone very much appreciated. thanks in advance..

Mabuhay!!!
__________________
Mabuhay!!!
 
Old July 24th, 2003, 08:00 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lillu
Default

Here you go:

<html>
<head>
<script language="javascript">
function checkBox(cbox)
{
box = eval(cbox);
box.checked = !box.checked;

changeBox();
}
function changeBox()
{
  if (document.ccform.ccNominatedBy.checked == true)
  {
    document.ccform.ccNominaterLN.disabled=true;
    document.ccform.ccNominaterFN.disabled=true;
    document.ccform.ccNominaterMN.disabled=true;
  }
  else
  {
      document.ccform.ccNominaterLN.disabled=false;
    document.ccform.ccNominaterFN.disabled=false;
    document.ccform.ccNominaterMN.disabled=false;
  }
}

</script>
</head>
<body>

<form name="ccform">

<input type="checkbox" name="ccNominatedBy">

<a class="chekbox" href="#" onClick="checkBox('document.ccform.ccNominatedBy') ;return false">Check it!</a><br>

<input type="text" name="ccNominaterLN" id="text1" value="Type some text">
<input type="text" name="ccNominaterFN" id="text2" value="Type some text">
<input type="text" name="ccNominaterMN" id="text3" value="Type some text">

</form>
</body>
</html>

Lillu


The Purple Couch
http://www.geocities.com/lillamarta
 
Old July 24th, 2003, 10:19 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lillu
Default

Hi again,

I enhanced the code a bit. Now it loops through the form and disables all elements that are textboxes (type == 'text')
It's more elegant and saves typing.

I used some standard notation this time (check1, text1 etc)

<html>
<head>
<script language="javascript">
function checkBox(cbox)
{
box = eval(cbox);
box.checked = !box.checked;

changeBox();
}
function changeBox()
{
 var max = document.forms[0].elements.length; //count all the elements in the form

 for (i=0; i<max; i++)
 {
  element = document.forms[0].elements[i];

  if (document.form1.check1.checked == true)
  {
    if (element.type == "text")
    {
    element.disabled=true;
    }
  }
  else
  {
    element.disabled=false;
  } //end if
 } // end for
} // end function
</script>
</head>
<body>

<form name="form1">

<input type="checkbox" name="check1">

<a class="chekbox" href="#" onClick="checkBox('document.form1.check1');return false">Check it!</a><br>

<input type="text" name="text1" id="text1" value="Type some text">
<input type="text" name="text2" id="text2" value="Type some text">
<input type="text" name="text3" id="text3" value="Type some text">

</form>
</body>
</html>

Lillu

The Purple Couch
http://www.geocities.com/lillamarta
 
Old July 28th, 2003, 04:45 AM
Authorized User
 
Join Date: Jun 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to vickriz
Default

Quote:
quote:Originally posted by lillu
 Hi again,

I enhanced the code a bit. Now it loops through the form and disables all elements that are textboxes (type == 'text')
It's more elegant and saves typing.

I used some standard notation this time (check1, text1 etc)

<html>
<head>
<script language="javascript">
function checkBox(cbox)
{
box = eval(cbox);
box.checked = !box.checked;

changeBox();
}
function changeBox()
{
var max = document.forms[0].elements.length; //count all the elements in the form

for (i=0; i<max; i++)
{
element = document.forms[0].elements[i];

if (document.form1.check1.checked == true)
{
    if (element.type == "text")
    {
    element.disabled=true;
    }
}
else
{
    element.disabled=false;
} //end if
} // end for
} // end function
</script>
</head>
<body>

<form name="form1">

<input type="checkbox" name="check1">

<a class="chekbox" href="#" onClick="checkBox('document.form1.check1');return false">Check it!</a><br>

<input type="text" name="text1" id="text1" value="Type some text">
<input type="text" name="text2" id="text2" value="Type some text">
<input type="text" name="text3" id="text3" value="Type some text">

</form>
</body>
</html>

Lillu

The Purple Couch
http://www.geocities.com/lillamarta
hi lillu..
i just used the first code you give me because i have a lots of text box on my page. i just give you those part that used the script.

the result using that script u give was causing an error that appear to the status page: "Error on page"

Mabuhay!!!
 
Old July 29th, 2003, 06:47 AM
Registered User
 
Join Date: Jul 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lillu
Default

Hi vickriz,

Can you show me your whole implementation so that I can debug it?
My script is correct, I tested it so there must be an issue when it's
combined with yours.

Lillu

The Purple Couch
http://www.geocities.com/lillamarta





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Need Help regards checkbox nellaikumar ASP.NET 1.0 and 1.1 Basics 1 December 1st, 2005 02:07 PM
CheckBox dkr72 C# 1 December 9th, 2004 11:27 AM
Checkbox johnjohn Classic ASP Basics 2 December 6th, 2004 06:03 PM
checkbox damnnono_86 Access 2 October 10th, 2003 03:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.