Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2003, 02:11 AM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, NCR, Philippines.
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!!!
Reply With Quote
  #2 (permalink)  
Old July 24th, 2003, 08:00 AM
Registered User
 
Join Date: Jul 2003
Location: Budapest, , Hungary.
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
Reply With Quote
  #3 (permalink)  
Old July 24th, 2003, 10:19 AM
Registered User
 
Join Date: Jul 2003
Location: Budapest, , Hungary.
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
Reply With Quote
  #4 (permalink)  
Old July 28th, 2003, 04:45 AM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, NCR, Philippines.
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!!!
Reply With Quote
  #5 (permalink)  
Old July 29th, 2003, 06:47 AM
Registered User
 
Join Date: Jul 2003
Location: Budapest, , Hungary.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:27 PM.


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