Solved

document.form.ckbox is null or not an object

Posted on 2008-06-24
7
231 Views
Last Modified: 2008-06-25
how can i fix this?
please help...i have 2 hours to fix it and i have no idea how:(
<script language="JavaScript">
function get_check_value()
{
      var c_value = "";
 
      for (var i=0; i < document.form.ckbox.length; i++)
      {
            if (document.form.ckbox[i].checked)
            {
                  c_value = c_value + document.form.ckbox[i].value + "\n";
            }
      }
 
      if ( c_value != "" )
      {
            getcustomer ( c_value );
      }
 
}
 
function getcustomer ( customer )
{
      // do something with the customer
      // then call return
}
</script>
 
 
<form action="" method="">
...
response.write "<p><input type=""checkbox"" name=""menu"" value='" & rstemp1("id") & "' >" & rstemp1("subcat") & "</p>"
...
</form>
 
<A href="#" onclick="get_check_value();">find values</A>

Open in new window

0
Comment
Question by:Forrest_Gump
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 21862911
The name is menu and not ckbox

Here is a safer script
<script language="JavaScript">
function get_check_value() {
  var theForm = document.forms[0]; // assuming first form and that elements have been wrapped in a form tag
  var c_value = "";
  if (theForm.menu.length) { // there may be only one
    for (var i=0; i < theForm.menu.length; i++) {
      if (theForm.menu[i].checked) c_value += theForm.menu[i].value+"\n";
    }
  }
  else if (theForm.menu.checked) c_value = theForm.menu.value+"\n"; // assuming getcustomer needs the trailing \n
  if (c_value != "") getcustomer(c_value);
  return false; // cancel the href 
}
 
function getcustomer ( customer )
{
      // do something with the customer
      // then call return
}
</script>
 
 
<form action="" method="">
...
response.write "<p><input type=""checkbox"" name=""menu"" value='" & rstemp1("id") & "' >" & rstemp1("subcat") & "</p>"
...
</form>
 
<A href="#" onclick="return get_check_value(); ">find values</A>
 
NOTE THE RETURN on the click

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21862944
do you generate form controls first clearly? lot of syntax errors on your form code
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 21863092
What syntax errors???

Missing values for method and action could just be because it is an example

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Forrest_Gump
ID: 21863346
document.form.ingrid is null or not an object:(
<form>
<%
...
response.write "<input type=""checkbox"" name=""ingrid"" value='" & rstemp1("id") & "' >" & rstemp1("subcat") & "<br>"
...
%>
 
<A href="#" onClick="showingr(get_check_value()); return false">find values</A>
</form>
 
 
 
.......
 
 
function get_check_value() {
  var c_value = "";
  for (var i=0; i < document.form.ingrid.length; i++) {
    if (document.form.ingrid[i].checked) {
      c_value = c_value + document.form.ingrid[i].value + "\n";
    }
  }
  return c_value; // may be empty
}
 
function showingr(customers) {
  if (customers=="") return; // leave the function
 
{ 
xmlHttpSel2=GetXmlHttpObject();
if (xmlHttpSel2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getcustomer.asp";
url=url+"?ingr="+customers;
url=url+"&sid="+Math.random();
xmlHttpSel2.onreadystatechange=ingrChanged;
xmlHttpSel2.open("GET",url,true);
xmlHttpSel2.send(null);
}
 
function ingrChanged() 
{ 
if (xmlHttpSel2.readyState==4)
{ 
document.getElementById("txtHint").value=xmlHttpSel2.responseText;
}
}
 
 
}

Open in new window

0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 500 total points
ID: 21863394
document.forms[0].ingrid !!!!!! if it is the FIRST form, change [0] to [1] for the second form and so on

And make sure your checkboxes are wrapped in a form tag

<form>
<%
...
response.write "<input type=""checkbox"" name=""ingrid"" value='" & rstemp1("id") & "' >" & rstemp1("subcat") & "<br>"
...
%>
</form>

I will not be online for a few hours now
0
 

Author Comment

by:Forrest_Gump
ID: 21863567
http://ilmc.brinkster.net/cpp/web/getcustomer.asp
that is not doing anything:(
i got no error but i am clicking on the
      <p><input type="CHECKBOX" name="ingrid" value="3"> ...and The Other</p>
and that is not going anywhere...
0
 

Author Comment

by:Forrest_Gump
ID: 21863773
dear mplungjan,
you soved the original question problem so i am closing this question and thakyou for that.
but the origianl problem was not solved so please help me here:
http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23513718.html
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question