p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   wierd error (http://p2p.wrox.com/showthread.php?t=32268)

crmpicco August 8th, 2005 06:34 AM

wierd error
 
Code:

<script>
// Sort Array (02-08-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

function zxcSelectSort(zxcid,zxcfirstoption)
{
// zxcid - 'city'
// zxcfirstoption - '1'


 zxcobj=document.getElementById(zxcid);
 zxcAry=new Array();
 for (zxc0=zxcfirstoption;zxc0<zxcobj.options.length;zxc0++)
 {
  zxcAry[zxc0-zxcfirstoption]=zxcobj.options[zxc0];
 }
 zxcAry=zxcAry.sort(zxcOptionSort);
 for (zxc1=0;zxc1<zxcAry.length;zxc1++)
 {
  zxcobj.options[zxc1+zxcfirstoption]=new Option(zxcAry[zxc1].text,zxcAry[zxc1].value,true,true);

  document.form.text.value=zxcAry[zxc1].text;
  document.form.zxcobj.value=zxcobj;
 }
}

function zxcOptionSort(zxca,zxcb)
{

 zxcA=zxca.text.toLowerCase();
 zxcB=zxcb.text.toLowerCase();
 document.form.test.value = zxca.text
 document.form.test2.value = zxcb.text
 if (zxcA<zxcB)
 {
     return -1;
 }
 if (zxcA>zxcB)
 {
     return 1;
 }
 return 0;
}



</script>

<body bgcolor="#f5f5f5" leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" onload="zxcSelectSort('city',1);">
<form name="form" id="form" method="post" action="destination4.asp">
<select name="city" id="city" style="font-size:9px" onChange="form.submit()">
<option value="empty"> </option>
<%
do until rscitycode.eof
set rsnotrains = con.execute("select DISTINCT Airportcode,CityCode from dbo_tp_airport where Citycode = '"& rscitycode("CityCode") &"' and Facilitycode = 'A'")
do until rsnotrains.eof

set rsnozug = con.execute("select DISTINCT CityName from dbo_tp_cityname where CityCode = '" & rsnotrains("CityCode") & "'")
do until rsnozug.eof
%>

<% if rsnozug("CityName") <> temp then %>
<option><%=rsnozug("CityName")%></option>
<%
end if
temp = rsnozug("CityName")
rsnozug.movenext
loop
rsnotrains.movenext
loop
rscitycode.movenext
loop
%>
</select>
</form>

I am having a wierd problem with this script.

When i INCLUDE the line:
Code:

document.form.zxcobj.value=zxcobj;
i get a 'null or not an object' error, but everything is passed to the next page and it works ok.

But when i take it out i get NO ERROR, but the following page (destination4.asp) doesnt work.

The 'city' form field is knocked out??



www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt

vinod_yadav1919 August 8th, 2005 10:50 AM

Hii Crmpicco!!

zxcobj=document.getElementById(zxcid); //It returns an object

document.form.zxcobj.value=zxcobj; //You Can't assign an object to value type

You can use
zxcobj.options[zxc0].Text
zxcobj.options[zxc0].Value

Again there is no form element in the form with name "zxcobj"
you need to eval function so that u can get right object then assign it's text/value to the required text/value

I think the below line will always give u an error
document.form.text.value=zxcAry[zxc1].text;

since there is no form element with "text" as name

use eval function to get required object ,then assign object value /text property to the value/text

Hope this will help you

Cheers :)

vinod


All times are GMT -4. The time now is 11:28 PM.

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