Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object required on xml tag

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
Hi there

I just need a little help with some issues i am having, using xml data islands.

I have the following function (stripped down currently for ease of debugging)

Code:
function testsubs(user)
{
var strQuery = "";
var objSelect = document.getElementById("group");

var id=objSelect.options[objSelect.selectedIndex].value;

strQuery="select s.subscriptionid, s.datestarted, s.dateexpires,  s.custommonthlyrate, t.subscriptiontypeid, t.name " + 
"from subscription s join subscriptiontype t on t.subscriptiontypeid = s.subscriptiontypeid " +
"where s.Level1GroupID = " + id;

xmlid.async = false;

xmlid.SRC="/cgi-bin/OSMOS.exe/getsubscription?QString=" + strQuery + "&id=" + user;
//ERROR OCCURS ON THE FOLLOWING LINE:
objName = xmlid.getElementsByTagName("name");
document.getElementById("name").value = objName.item(0).text;
alert("complete");
}

When i execute this function, xmlid.SRC is as follows:

Code:
<?xml version="1.0"?>
 <subscriptions>
 <subscription>
  <name><![CDATA[Free]]></name>
  <datestarted><![CDATA[25/10/2006 1:26:09 p.m.]]></datestarted>
  <dateexpires><![CDATA[]]></dateexpires>
  <custommonthlyrate><![CDATA[]]</custommonthlyrate>
  <subscriptiontypeid><![CDATA[1]]</subscriptiontypeid>
  <subscriptionid><![CDATA[2]]</subscriptionid>
 </subscription>
</subscriptions>

My problem is occurring on line "objName = xmlid.getElementsByTagName("name");" I receive an error message from IE "Object required" (so informative too)

here is the html in question (again stripped down for simplicity):

Code:
<xml id="xmlid"></xml>
<form name="groupform" id="groupform" method="post" class="shown" form action="[URL unfurl="true"]http://aphrodite/cgi-bin/osmos.exe/savesubscription"[/URL]
 class=shown onSubmit="return submitonce()">
<input type="hidden" name="ID" value="29">
<table class="post" BGColor="#F4BAD8" width=100%>
<tr BGColor="#F4BAD8">
<td colspan="5">
<h4>Current Subscriptions</h4>
</td><td align=right>
<input type="submit" name="addnew" value="Add New" ID="submitbutton" class="buttontext" onMouseOver="this.className='buttonover';" onMouseOut="this.className='buttontext';" onClick="changeElementClass('addnew', 'shown');">
</td><td></td></tr>
<tr BGColor="#F4BAD8">
<td>
Group 
</td><td>
<select name="group" id="group" onChange="testsubs(29);">  //function called
<option value="-1">[SELECT]</option>
<option value="58">DFCoGroup</option>
<option value="60">FrankBobGroup</option>
<option value="68">SithTGroup</option>
<option value="70">CatalystGroup</option>
<option value="55">MadsoftGroup</option>
</select>
</td></tr>
</table>
</form>


<form action="[URL unfurl="true"]http://aphrodite/cgi-bin/osmos.exe/savesubscription"[/URL] name="addnew" method=post id="addnew" onSubmit="return submitonce()"  class="hidden">
        <input type="HIDDEN" name="ID" value ="29">
<table class="post" BGColor="#F4BAD8" width=100%>
  
  <tr BGColor="#F4BAD8">
    <td><strong>Name</strong></td><td><input type="text" id="name" name="name" value=""></td></tr>
  
    </td></tr>
</table>
</form>

Can anyone here see what is going wrong with this?? I use this code in many places and it works, so surely i am just missing something obvious??


[cheers] cheers in advance (of course if things go as usual, i will solve this myself within the next 5 minutes after posting this) [ponder]

Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
[1] This is one major problem as I see it. You've to encode the query string.
[tt]
strQuery="select s.subscriptionid, s.datestarted, s.dateexpires, s.custommonthlyrate, t.subscriptiontypeid, t.name " + "from subscription s join subscriptiontype t on t.subscriptiontypeid = s.subscriptiontypeid " + "where s.Level1GroupID = " + id;
[blue]strQuery=strQuery.replace(/ /g,"+");[/blue]
[/tt]
[2] Other minor details may be due to you strip the script down too much?
[2.1]
><select name="group" id="group" onChange="testsubs(29);"> //function called
Comment in the page other than the script should be <!-- -->?
[tt]<select name="group" id="group" onChange="testsubs(29);"> <!-- function called -->[/tt]
[2.2] There seems to have an orphan [tt]</td></td>[/tt] inside the form.
[2.3] This line can be simplified.
>var id=objSelect.options[objSelect.selectedIndex].value;
[tt]var id=objSelect.value;[/tt]

[3] To make sure there isn't parsing error etc., you can always put a line just before the getElementsByTagName, namely this.
[tt] alert(xmlid.xml); //ie specific[/tt]
Then you can be sure during debugging thing set up correctly.
 
Well, bearing in mind that this code works in other places... Billy AFAIK xmlid is declared in the html
Code:
<xml id="xmlid"></xml>

(Bearing in mind this xml data island stuff only works in IE) If you have a solution that is cross-browser i'm all ears. [bigears]

I would love to be able to link you to some working code, but the data is generated from my Db and fed back dynamically as a response object into my secure app..

TSUJI...
my comments are in the wrong format (correct) but i only added them for my post and they are not in my actual code. Orphan </td> tags or more than likely due to my stripping down.

anyway, here is a complete html page that SHOULD work check it out.. (note comments on where it fails)

Code:
<head>
<script>
function testsubs(user)
{
var strValue = "";
var strQuery = "";

strValue = document.getElementById("name1").value;
//strValue is undefined here -- why?
alert("2 " + strValue.Value);

xmlid.async = false;

xmlid.SRC='<?xml version="1.0"?><subscriptions><subscription><name><![CDATA[Free]]></name></subscription></subscriptions>';

testObj = xmlid.getElementsByTagName("name");
alert("3 - debug");

//fails on this line below (object required when referencing object item(0).text)
strValue = testObj.item(0).text;
alert("4 " + strValue.Value);
document.getElementById("name1").value = testObj.item(0).text;
}
</script>
</head>
<body>

<xml id="xmlid"></xml>
<form name="groupform" id="groupform" method="post" form action="[URL unfurl="true"]http://mydomain/cgi-bin/myapp.exe/savesubscription"[/URL] onSubmit="return submitonce()">
<input type="hidden" name="ID" value="29">
<table BGColor="#F4BAD8" width=100%>
<tr BGColor="#F4BAD8">
  <td colspan=2>
    <h4>Current Subscriptions</h4>
  </td>
 </tr>
<tr BGColor="#F4BAD8">
<td>
Group 
</td><td>
<select name="group" id="group" onChange="testsubs(29);">
<option value="-1">[SELECT]</option>
<option value="58">DFCoGroup</option>
<option value="60">FrankBobGroup</option>
<option value="68">SithTGroup</option>
<option value="70">CatalystGroup</option>
<option value="55">MadsoftGroup</option>
</select>
</td></tr>
</table>
</form>


<form action="[URL unfurl="true"]http://aphrodite/cgi-bin/osmos.exe/savesubscription"[/URL] name="addnew" method=post id="addnew">
<table class="post" BGColor="#F4BAD8" width=100%>
 <tr><td>
<input id="name1" name="name1" value="blah">
  
    </td></tr>
</table>
</form>

</body>



Tracey
Remember... True happiness is not getting what you want...

Its wanting what you have got!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top