Click to See Complete Forum and Search --> : checkbox not availeable(simple problom)
shaba
11-09-2003, 03:40 AM
i have a checkbox in my form.name is checkbox1
i want to call a function while checking checkbox
inside javascript function i want to reference this checkbox.i wrote code like this
var f=document.form1
if(checkbox1.checked){
---
---
}
an error message displaying that checkbox1 is null or not an object.
why so?
how can i reference this checkbix object within javascript function inside <head></head>tags??.
anyone plz..thanks in adv
Charles
11-09-2003, 05:32 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {margin:0 1ex}
-->
</style>
<script type="text/javascript">
<!--
function showState (e) {if (e.type == 'checkbox') alert ([e.nextSibling.data, 'is', e.checked ? 'checked.' : 'unchecked.'].join(' '))}
// -->
</script>
<form action="">
<div>
<label><input onclick="showState(this)" type="checkbox">Foo</label>
</div>
</form>
shaba
11-09-2003, 11:18 AM
hi charles,
that's a good idea to pass the current object to the function.
but that does'nt solve my problom.i dont have much experience in JS.i am a C++ programmer.
i need to reference more objects within function ..like this
function coo(v){
if(v.checked){
document.form1.textfield1.value=document.form1.textfield5.value;
---
---so and so
}
}
how can i resolve this situation?.
Charles
11-09-2003, 12:43 PM
See my post at http://forums.webdeveloper.com/showthread.php?s=&threadid=20945.
shaba
11-10-2003, 01:09 AM
hi charles,
i hav tried it(same code).but it's not working in IE6 and mozilla(latest) ..how can i resolve?
an error displaying about lack of availeability of objects
Charles
11-10-2003, 04:32 AM
It's likely that you are doing womething wrong. As I don't have access to your page all I can suggest is that you stop doing that wrong thing.
shaba
11-12-2003, 04:08 AM
i have tried to resolve this problom hardly in 3 days .i tried lot of ways.but i could'nt understand the reason behind the error.so i determined to send the code here.
please check the code and help me
thx in adv
code
<html>
<head>
<title>NewPage1</title><script language="JavaScript">
//Begin CCS script
//Include JSFunctions @1-DA3E7A20
</script>
<script language="JavaScript" src="functions.js"></script>
<script language="JavaScript">
//End Include JSFunctions
function verifyPassword(P,VP){
var P1 = P //creates string object for string values passed
var VP1 = VP
if (P1.length < 6){
return "The password you select needs to be between six and twenty characters.\nPlease enter a different password and submit again.";
}
else if (P1.length > 20){
return "The password you select needs to be between six and twenty characters.\nPlease enter a different password and submit again.";
}
else if (VP1.length != 0) {
if (P1.length == VP1.length){
for (var i=0; i < P1.length ; i++){
if (P1.charAt(i) != VP1.charAt(i)){
return "The Confirm Password field does not match the first Password field.\nPlease reenter this information and submit again.";
}
}
}
else{
return "The Confirm Password field does not match the first Password field.\nPlease reenter this information and submit again.";
}
}
else if (VP1.length ==0){
return "The Confirm Password field does not match the first Password field.\nPlease reenter this information and submit again.";
}
return "OK";
}
function SetMailFields(e){
this.billingcity_Name.value=e.city_Name.value;
e.billingcountryid_Name.value=e.countryid_Name.value;
e.billingzip_Name.value=e.zip_Name.value;
}
//page_OnUnload @1-2C151293
function page_OnUnload()
{
var result;
//End page_OnUnload
//Validate Entry @32-6DA7922E
this.ccsCaption = "";
//End Validate Entry
//Close page_OnUnload @1-BC33A33A
return result;
}
//End Close page_OnUnload
//bind_events @1-78991E9E
function bind_events() {
window.onunload = page_OnUnload;
forms_onload();
}
//End bind_events
window.onload = bind_events; //Assign bind_events @1-19F7B649
//End CCS script
</script>
</head>
<body>
<p>{Header}</p>
<p>
<!-- BEGIN Record users -->
<form name="{HTMLFormName}" action="{Action}" method="post">
<table>
<!-- BEGIN Error -->
<tr>
<td colspan="2">{Error}</td> <b>Login</b>
</tr>
<!-- END Error -->
<tr>
<td>Login*</td>
<td><input maxlength="15" size="15" value="{user_login}" name="{user_login_Name}"> </td>
</tr>
<tr>
<td>Password *</td>
<td>
<p><input type= password maxlength="15" size="15" value="{user_password}" name="{user_password_Name}"></p>
</td>
</tr>
<tr>
<td>Confirm Password *</td>
<td>
<p><input type= password maxlength="15" size="15" value="{confirm_password}" name="{confirm_password_Name}"></p>
</td>
</tr>
</table>
<p>
<hr>
<table>
<b>Personal profile</b>
<tr>
<td>First Name* </td>
<td><input maxlength="20" value="{first_name}" name="{first_name_Name}"> </td>
</tr>
<tr>
<td>Last Name*</td>
<td><input maxlength="20" value="{last_name}" name="{last_name_Name}"> </td>
</tr>
<tr>
<td>Email* </td>
<td><input maxlength="64" size="50" value="{email}" name="{email_Name}"> </td>
</tr>
<tr>
<td>Country*</td>
<td>
<select name="{country_id_Name}">
<option value="" selected>Select Value</option>
{country_id_Options}
</select>
</td>
</tr>
<tr>
<td>State*</td>
<td><input maxlength="36" size="36" value="{state}" name="{state_Name}"> </td>
</tr>
<tr>
<td>City* </td>
<td><input maxlength="30" size="30" value="{city}" name="{city_Name}"> </td>
</tr>
<tr>
<td>Zip/postal*</td>
<td><input maxlength="10" size="10" value="{zip}" name="{zip_Name}"> </td>
</tr>
<tr>
<td>Company</td>
<td><input maxlength="36" size="36" value="{company}" name="{company_Name}"> </td>
</tr>
<tr>
<td>Address1* </td>
<td><input maxlength="50" size="50" value="{address1}" name="{address1_Name}"> </td>
</tr>
<tr>
<td>Address2* </td>
<td><input maxlength="50" size="50" value="{address2}" name="{address2_Name}"> </td>
</tr>
<tr>
<td>Address3 </td>
<td><input maxlength="50" size="50" value="{address3}" name="{address3_Name}"> </td>
</tr>
<tr>
<td>Phone Day</td>
<td><input maxlength="20" value="{phone_day}" name="{phone_day_Name}"> </td>
</tr>
<tr>
<td>Phone Evn </td>
<td><input maxlength="20" value="{phone_evn}" name="{phone_evn_Name}"> </td>
</tr>
<tr>
<td>Fax </td>
<td><input maxlength="20" value="{fax}" name="{fax_Name}"> </td>
</tr>
<tr>
<td>Notes </td>
<td><textarea name="{notes_Name}" rows="3" cols="50">{notes}</textarea> </td>
</tr>
</table>
<input type="checkbox" name="copy"
onclick="SetMailFields(this.form);">My billing information is the same as my personal address.
<hr><b>Enter billing information</b>
<table>
<tr>
<td>Country </td>
<td>
<select name="{billingcountryid_Name}">
<option value="" selected>Select Value</option>
{billingcountryid_Options}
</select>
</td>
</tr>
<tr>
<td>City </td>
<td><input maxlength="36" size="36" value="{billingcity}" name="{billingcity_Name}"> </td>
</tr>
<tr>
<td>Zip </td>
<td><input maxlength="10" size="10" value="{billingzip}" name="{billingzip_Name}"> </td>
</tr>
<tr>
<td>Address1 </td>
<td><input maxlength="96" size="50" value="{billingaddress1}" name="{billingaddress1_Name}"> </td>
</tr>
<tr>
<td>Address2 </td>
<td><input maxlength="96" size="50" value="{billingaddress2}" name="{billingaddress2_Name}"> </td>
</tr>
<tr>
<td>Address3 </td>
<td><input maxlength="96" size="50" value="{billingaddress3}" name="{billingaddress3_Name}"> </td>
</tr>
<tr>
<td align="right" colspan="2">
<!-- BEGIN Button Button_Insert --><input type="submit" value="Submit" name="{Button_Name}" onSubmit="submitMe();"><!-- END Button Button_Insert --> </td>
</tr>
</table>
<p></p>
<p></p>
</form>
<!-- END Record users -->
<p></p>
<p> {Footer} </p>
</body>
</html>
Charles
11-12-2003, 05:04 AM
Before you try learning JavaScript you need to learn HTML. Read, mark, learn and inwardly digest the HTML 4.01 Specification (http://www.w3.org/TR/html4/). And once you can get your page to pass the official Validator (http://validator.w3.org/) as HTML 4.01 Strict find someone else to do the JavaScript for you. And note that ...From the HTML 4.01 Specification:
Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. Additionally, when used with graphics, these tables may force users to scroll horizontally to view a table designed on a system with a larger display. To minimize these problems, authors should use style sheets to control layout rather than tables.
http://www.w3.org/TR/html4/struct/tables.html#h-11.1