Solved

document.form.ckbox is null or not an object

Posted on 2008-06-24
7
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 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