ITsolutionWizard
asked on
xml, jquery, complex
In jquery, is it possible to find element then get the rest of the nodes(outside of original element)?
E.g.
If i pass you BondName = abc and if it is found, then output me everything within <additionalInformation>?
E.g.
If i pass you BondName = abc and if it is found, then output me everything within <additionalInformation>?
<Surety>
<SuretyLine>
<Commercial>
<Bond>
<General Information>
<BondName>abc</BondName>
</General Information>
<AddtionalInformation>
<div class="col-lg-12">
<Input Type="text" Name="additionalInfo_licenseNo" ID="additionalInfo_licenseNo" Onchange="fnSaveSingleData(this.name,'1')" Placeholder="Enter License No." Class="form-control" Title="License is required!" PrefillValue="No" Required="" />
</div>
</AddtionalInformation>
</Bond>
<Bond>
<General Information>
<BondName>xyz</BondName>
</General Information>
<AddtionalInformation>
<div class="col-lg-12">
<Input Type="text" Name="additionalInfo_licenseNo" ID="additionalInfo_licenseNo" Onchange="fnSaveSingleData(this.name,'1')" Placeholder="Enter License No." Class="form-control" Title="License is required!" PrefillValue="No" Required="" />
</div>
</AddtionalInformation>
</Bond>
</Commercial>
</SuretyLine>
</Surety>
Since you have jQuery as one of the topic areas, you can try using .siblings() - https://api.jquery.com/siblings/
ASKER
??? I have no idea what you mean. Please show me the codes to demo. Thanks
The code examples in the API documentation didn't make sense?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One more time, we already answered this very simple question in your previous posts.
If you don't go forward on your previous questiond I, personaly :), don't see any interest to ask the same question using a new formulation
I would be happy to discuss with you if you're not agree about this.
You let question opened.
And yes, you asked the same question.
If you don't go forward on your previous questiond I, personaly :), don't see any interest to ask the same question using a new formulation
I would be happy to discuss with you if you're not agree about this.
You let question opened.
And yes, you asked the same question.
If element contains the node for ABC then you can do
element.parent().find('.AddtionalInformation');
ASKER
I try below. and not working. any ideas?
<script>
function fnGetBondAdditionalInformation() {
$.ajax({
url: "http://localhost:5489/BondList.xml",
success: function (xml) {
parseSelectXMLBondAdditionalInformation(xml, "test", localStorage.getItem('bondState'), localStorage.getItem('bondName'))
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Status: " + xhr.status);
alert("Error: " + thrownError);
}
});
}
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
var html = "";
$(xml).find('Bond').each(function (i, e) {
{
if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {
var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
var selectedAdditionalInforation = $(e).find('AddtionalInformation').find('div').find('Input').text();
$('#test').text(selectedAdditionalInforation);
}
}
});
// alert(html);
}
window.onload = function () {
fnGetBondAdditionalInformation();
};
</script>
<script>
</script>
Share a link to your page so we can check your page online
ASKER
That is all i have below
<script>
function fnGetBondAdditionalInformation() {
$.ajax({
url: "http://localhost:5489/BondList.xml",
success: function (xml) {
parseSelectXMLBondAdditionalInformation(xml, "test", localStorage.getItem('bondState'), localStorage.getItem('bondName'))
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Status: " + xhr.status);
alert("Error: " + thrownError);
}
});
}
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
var html = "";
$(xml).find('Bond').each(function (i, e) {
{
if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {
var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
var selectedAdditionalInforation = $(e).find('AddtionalInformation').find('div').find('Input').text();
$('#test').text(selectedAdditionalInforation);
}
}
});
// alert(html);
}
window.onload = function () {
fnGetBondAdditionalInformation();
};
</script>
<p id="test"></p>
Where to test it ?
ASKER
U can just copy and paste the codes...
I would like to test it in your environment, not mine because if I say it work on my side, we blocked !
Look at this line of code
Please advise - either post XML with valid data or explain what it is you want do because your code does not match your data.
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName)
Now look at this line of codeif (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {
Now look at your GeneralInformaion block in your XML<General Information>
<BondName>abc</BondName>
</General Information>
There is no State value in your XMLPlease advise - either post XML with valid data or explain what it is you want do because your code does not match your data.
Having looked at your code there are a number of other issues you need to look at.
1. You have invalid tags in your XML General Information has spaces in the name - this is not valid XML the element becomes General with an empty attribute Information
2. You are then searching for the text() of an Input - an Input does not have a text component.
The code below is sort of going in the direction of what you want - but you need to tell us
a) What your data looks like - the XML you have posted is incomplete and invalid
b) What data you want from the XML
How to get the value of AdditionaInformation based on selected BondName
1. You have invalid tags in your XML General Information has spaces in the name - this is not valid XML the element becomes General with an empty attribute Information
2. You are then searching for the text() of an Input - an Input does not have a text component.
The code below is sort of going in the direction of what you want - but you need to tell us
a) What your data looks like - the XML you have posted is incomplete and invalid
b) What data you want from the XML
How to get the value of AdditionaInformation based on selected BondName
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
var html = "";
$(xml).find('Bond').each(function (i, e) {
{
var gi = $(e).find('GeneralInformation');;
if (gi.find('BondName').text() == bondName) {
var ai = gi.parent().find('AddtionalInformation');
var text = ai.find('div > Input');//.text();
// THIS OUTPUTS AN EMPTY STRING BECAUSE input ELEMENTS
// DON'T HAVE A text PORTION
console.log(text);
}
}
});
// alert(html);
}
ASKER
Below is the data i want on html append
<div class="col-lg-12">
<Input Type="text" Name="additionalInfo_licen seNo" ID="additionalInfo_license No" Onchange="fnSaveSingleData (this.name ,'1')" Placeholder="Enter License No." Class="form-control" Title="License is required!" PrefillValue="No" Required="" />
</div>
<div class="col-lg-12">
<Input Type="text" Name="additionalInfo_licen
</div>
ASKER
any helps?
You have not answered the issues I raised in my earlier post. For me to help you you need to work with me.
There are errors in your XML and your code which tells me you have not given us everything we need to see. I cannot give you a solution without understanding the problem space - you need to address the issues I raised in my previous post.
There are errors in your XML and your code which tells me you have not given us everything we need to see. I cannot give you a solution without understanding the problem space - you need to address the issues I raised in my previous post.
ASKER
what is your question? I think i already answered them. Thanks
1. You have invalid tags in your XML General Information has spaces in the name - this is not valid XML the element becomes General with an empty attribute Information
2. You are then searching for the text() of an Input - an Input does not have a text component.