Webmaster Forum

Bidding Directory   Improve your ranking, submit to directories   V7N Directory
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Reply
 
LinkBack Thread Tools Display Modes
Old 07-06-2004, 08:36 PM   #1 (permalink)
Inactive
 
Join Date: 07-06-04
Posts: 5
iTrader: 0 / 0%
Latest Blog:
None

chrissyPH is liked by many
Checkbox and textbox relationship.....

hi there guys,

just want to ask some help with regards to my javascript problem. I have a listing of multiple checkbox and hidden textbox beside of it and want to disable the checkbox in case the textbox contains no value. What I want is to used only single id or name for checkbox and textbox, as I tried it on a single line, it works fine, but as i add new line with same checkbox and textbox ID/name then the problem happens.

here's my attemp:
<html>

<head>

<title>Test Page</title>
<script>
function CheckMe ()
{
if
(document.getElementById('2').value=="")

document.getElementById('1').disabled = true;
else
document.getElementById('1').disabled = false;

}
</script>
</head>

<body onload="CheckMe ()">

<form >

<p><input type="text" name="testbox" id="2" size="20"><input type="checkbox" name="checkboxtest" id="1" value="ON"></p>
<p><input type="text" name="testbox" id="2" size="20" value=""><input type="checkbox" name="checkboxtest" id="1" value="ON"></p>
</form>

</body>

</html>



regards,
Chrissy
chrissyPH is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 07-06-2004, 09:39 PM   #2 (permalink)
No Longer Here
 
Join Date: 09-27-03
Location: State College, PA
Posts: 9,354
iTrader: 0 / 0%
Latest Blog:
None

Jazzee is liked by somebodyJazzee is liked by somebodyJazzee is liked by somebodyJazzee is liked by somebodyJazzee is liked by somebody
I don't know javascript. How many of these are you putting on the page? Maybe it would be easier to use different id's for each one?...
Jazzee is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-06-2004, 10:09 PM   #3 (permalink)
v7n Mentor
 
imaginemn's Avatar
 
Join Date: 02-18-04
Location: Minneapolis, Minnesota
Posts: 1,941
iTrader: 0 / 0%
imaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to allimaginemn is a name known to all
Send a message via MSN to imaginemn Send a message via Yahoo to imaginemn Send a message via Skype™ to imaginemn
Try this. Remember that JavaScript starts with 0 and not 1. The form fields are counted in the order they display on the page.

[code:1:2257904064]<html>

<head>

<title>Test Page</title>
<script type="text/javascript">
//<![CDATA[
function disable_all() {
//enter all form fields needed to be disabled
document.forms[0][1].disabled = true;
document.forms[0][3].disabled = true;
}

function toggle(x,y){
if (document.forms[0][x].value == 0) {
document.forms[0][y].disabled = true;
} else {
document.forms[0][y].disabled = false;
}
}
//]]>
</script>
</head>

<body onload="disable_all();">

<form >

<p><input type="text" name="testbox" id="2" size="20" onKeyDown="toggle(0,1);" ><input type="checkbox" name="checkboxtest" id="1" value="ON"></p>
<p><input type="text" name="testbox" id="2" size="20" value="" onKeyDown="toggle(2,3);"><input type="checkbox" name="checkboxtest" id="1" value="ON"></p>
<input type="text">
<input type="submit" name="submit">
</form>

</body>

</html> [/code:1:2257904064]

imaginemn
__________________
Imagine Creative Services
Design : Marketing : Multimedia : More
imaginemn is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-07-2004, 12:12 AM   #4 (permalink)
Inactive
 
Join Date: 07-06-04
Posts: 5
iTrader: 0 / 0%
Latest Blog:
None

chrissyPH is liked by many
HI guys,

to give you the clear picture of what I'm trying to do, if the number selection contains no value the checkbox should be disabled, if has a value the checkbox is clickable. The content is dynamically generated(iterated), i dont know the exact amount of data being displayed that's why im only using one name for checkbox and one name for hidden textbox.

regards,
Chrissy


[code:1:4720b1db25]<html>
<HEAD>
</HEAD>
<BODY leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0" bgcolor="#FFFFFF" >
<DIV align=center>
<TABLE cellSpacing=1 width="100%" align=center border=0 VALIGN="TOP">
<tr>
<td valign="middle" bgcolor="#000000" class="moduleAction">Mobile Number Search&nbsp;
</td>
</tr>
<tr>
<td align="center">
<br>
</td>
</tr>
<tr>
<td width="100%">
<div align="left">
<table border="0" cellspacing="0" width="100%" cellpadding="0">
<tr>
<td width="100%" class="boxwhole">
<div align="left">
<table border="0" cellpadding="2" width="100%">
<tr>
<td width="100%">
</td>
</tr>
<tr>
<td width="100%" class="contentItalic">
<form name="destinationSearchForm">
<table border="0" cellspacing="1" width="100%">
<tr>
<td width="20%" class="Param">Search
By: :</td>
<td width="70%" class="ParamValue">
<input type="text" name="search" value="" class="textbox" id="T1"> by
<select name="criteria" class="textbox" id="D1"><option value="mobileNumber" selected="selected">Mobile Number</option>
<option value="lastName">Last Name</option>
<option value="firstName">First Name</option>
<option value="department">Department</option>
<option value="section">section</option></select>
<input type="button" value="Go" class="button" onclick="window.location='#'">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td width="100%" align="center">
</td>
</tr>
<tr>
<td width="100%">
<table border="0" cellspacing="1" width="100%">
<tr>
<td width="100%">
<table border="0" cellspacing="1" width="100%">

<tr>
<td width="50%" class="recordcount">Displaying 1 - 20 out of&nbsp; 328 records</td>
<td width="50%" class="recordcount"><p align="right">
First |


Prev |

<b><a href="#">Next</a></b>&nbsp; |
<b><a href="#">Last</a></b>

</td>
</tr>

</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100%" bgcolor="#000000">
<div align="right">
<table border="0" cellspacing="1" width="100%">
<tr>
<td width="100%" bgcolor="#FFFFFF">
<div align="right">
<table border="0" cellspacing="1" width="100%">
<tr>
<td width="1%" class="columnTitle"></td>
<td width="25%" class="columnTitle">Mobile Number</td>
<td width="25%" class="columnTitle">Name</td>
<td width="25%" class="columnTitle">Department</td>
<td width="26%" class="columnTitle">Section</td>
</tr>
<form name="destinationCheckBoxForm">
<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" name="mobCheckBox" value='09999990305'>

</td>
<td class="rowcontentColor1Center">
&nbsp;099990305
</td>
<td class="rowcontentColor1">
Name 1
</td>
<td class="rowcontentColor1">
Office of the Comptroller
</td>
<td class="rowcontentColor1">
Bills Processing Department
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">
</td>
<td class="rowcontentColor1">
Name 2
</td>
<td class="rowcontentColor1">
National Dealer Sales
</td>
<td class="rowcontentColor1">
Office of the National Dealer Sales Head
</td>
</tr>
<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 3
</td>
<td class="rowcontentColor1">
Office of the Treasurer
</td>
<td class="rowcontentColor1">
Disbursements
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>

</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 4
</td>
<td class="rowcontentColor1">
National Dealer Sales
</td>
<td class="rowcontentColor1">
Office of the National Dealer Sales Head
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 5
</td>
<td class="rowcontentColor1">
Power System
</td>
<td class="rowcontentColor1">
Office of the Power System Head
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">

<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 6
</td>
<td class="rowcontentColor1">
Product Development
</td>
<td class="rowcontentColor1">
Product Development Group
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>

</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 7
</td>
<td class="rowcontentColor1">
Marketing Services
</td>
<td class="rowcontentColor1">
Marketing &amp; Events
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>

</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 8
</td>
<td class="rowcontentColor1">
Project Management
</td>
<td class="rowcontentColor1">
Office of the Project Management Head
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">



<input type="checkbox" disabled name="mobCheckBox" value=''>



</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 9
</td>
<td class="rowcontentColor1">
Acquisition
</td>
<td class="rowcontentColor1">
Office of the Acquisition Head
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">



<input type="checkbox" disabled name="mobCheckBox" value=''>



</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 10
</td>
<td class="rowcontentColor1">
National Dealer Sales
</td>
<td class="rowcontentColor1">
Central/North Luzon Dealer Sales
</td>
</tr>
<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" name="mobCheckBox" value='09998072981'>

</td>
<td class="rowcontentColor1Center">
&nbsp;09998072981
</td>
<td class="rowcontentColor1">
Name 12
</td>
<td class="rowcontentColor1">
IT
</td>
<td class="rowcontentColor1">
IT
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">

</td>
<td class="rowcontentColor1">
Name 13
</td>
<td class="rowcontentColor1">
International Carrier Accounts
</td>
<td class="rowcontentColor1">
International Carrier Accounts
</td>
</tr>

<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">
</td>
<td class="rowcontentColor1">
Name 14
</td>
<td class="rowcontentColor1">
Office of the Comptroller
</td>
<td class="rowcontentColor1">
Financial Accounting Department
</td>
</tr>
<tr>
<td class="rowcontentColor1Center">
<input type="checkbox" disabled name="mobCheckBox" value=''>
</td>
<td class="rowcontentColor1Center">
</td>
<td class="rowcontentColor1">
Name 15
</td>
<td class="rowcontentColor1">
Sales Administration &amp; Control
</td>
<td class="rowcontentColor1">
Sales Administration &amp; Control
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="recordcount" width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">

<tr>
<td width="50%" class="recordcount">
<span>Page (17) &nbsp;
1 |

<b><a href="#">2</a></b> <a href="#"> </a> |

<b><a href="#">3</a></b> |
</span>
</td>
<td width="50%" class="recordcount"><p align="right">First | Prev |
<b><a href="#">Next</a></b> |
<b><a href="#">Last</a></b>

</td>
</table>
</td>
</tr>
</table>
<p align="center"><br>
<input type="submit" value="Add" onclick="window.location='#'" class="button" id="B3">&nbsp;&nbsp;
<input type="button" value="Cancel" name="B3" class="button">
</td>
</tr>
<tr>
<td width="100%"></td>
</tr>
<tr>
<td width="100%"><br>
</td>
</tr>
<tr>
<td width="100%" class="content" align="center">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</TABLE></DIV>
</form>
</BODY>
</html>

[/code:1:4720b1db25]
chrissyPH is offline  
Add Post to del.icio.us
Reply With Quote
Old 07-07-2004, 02:37 AM   #5 (permalink)
Moderator
 
LazyJim's Avatar
 
Join Date: 10-13-03
Location: UK
Posts: 2,819
iTrader: 0 / 0%
Latest Blog:
None

LazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to allLazyJim is a name known to all
Send a message via MSN to LazyJim
Couple of things to remember...
Never use just a number for an ID, (start with a letter or _).
ID's are unique don't let anyone make more thant one element with the same ID.

If you need to disable an unknown amount of checkboxs put them all inside <span id="myCheckboxs"> ... </span> then to disable them all do...[code:1:7391e0e047]
var chbxs = document.getElementById("myCheckboxs").getElements ByTagName("INPUT");
// asuming the only input fields here are the correct type loop throught them all and disable each one...
for (var i in chbxs) {
chbxs[i].disabled = true;
}

// or if there are different INPUT tags within the <span> you need to add a check for the type="checkbox"...
for (var i in chbxs) {
if (chbxs[i].type == "checkbox") chbxs[i].disabled = true;
}[/code:1:7391e0e047]
__________________

-LJ-

My advice is to look at each case individually, with an informed mind and an appropriately balanced and objective viewpoint.

Web Design and Development, Ipswich, UK.
My deviantArt
LazyJim is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
a simple checkbox question Kathryn Beach Coding Forum 2 05-22-2006 01:10 PM
Add text from button to textbox script Jason Coding Forum 4 03-19-2005 08:47 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 05:00 AM.
© Copyright 2008 V7 Inc