Before i submit my problem just to let you know i've been using jquery and javascripting for about a month or 2 now so i appologise in advance if this is something stupid.
Basicaly I have created a form with
"<select><option></option></select>" using jquery/javascript.
My main issue is that i want this to select from a database so i found out that you can get information from php files i just couldn't figure out how to get the variables it submits. I then found out that i can use xml to get the information to the script. but the code i have written doesn't seem to display anything. The code in red is what i think the issue is.
- //Default rows is 0
- var Count = 0;
-
- //Get Id for form location
- Location=document.getElementById('Login');
- //Create form
- Form=document.createElement("form");
- //Create Select
- Select=document.createElement("select");
-
- //Set default data to NULL
- var data = "";
- //Get information from test.php
- $.get('test.php', function(theXML) {
- $('client',theXML).each(function(i){
- //Grab total amount of rows from xmlTag row
- var Count=$(this).find("Row").text();
- //Duplicate options using the fallowing
- for(i=0; i<Count; i++) {
- //Create option element
- Option=document.createElement("option");
-
- //Get Name for option
- Name=$(this).find("Name").text();
-
- //Grab Customers Id for Value
- Id=$(this).find("Id").text();
-
- //Create Text node using Name
- Text=document.createTextNode(Name);
-
- //Assign Text to Option
- Option.appendChild(Text);
-
- //Set Value as Id
- $(Option).attr('value', Id);
- //Assign option to Select Element
- Select.appendChild(Option);
- }
-
- });
-
- });
-
- Location.appendChild(Form);
- Form.appendChild(Select);
Before doing the above I checked to see if it would work so i done the fallowing script.
- //Default rows is 0
- var Count = 2;
-
- //Duplicate options using the fallowing
- for(i=0; i<Count; i++) {
- //Create option element
- Option=document.createElement("option");
-
- //Create Text node using Name
- Text=document.createTextNode('Name');
-
- //Assign Text to Option
- Option.appendChild(Text);
-
- //Set Value as Id
- $(Option).attr('value', 'Id');
- //Assign option to Select Element
- Select.appendChild(Option);
- }
-
- Location.appendChild(Form);
- Form.appendChild(Select);
And it worked so am sure the issue revolves around grabbing the information from the php file
this is how the information looks in the php file after php has extracted it from mysql and submited it.
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <client>
- <count>
- <Row>2</Row>
- </count>
-
- <person>
- <Id>1</Id>
- <Name>Steve</Name>
- </person>
-
- <person>
- <Id>2</Id>
- <Name>Bill</Name>
- </person>
- </people>
I also tried just using an XML file with the above information and this did not work either.
Am just not sure as to how i could get the the fallowing information from the mysql database to the script
"`Id`, `Name` Count(total amount of customers)". Thanks in advance for any help or sugestion provided...
p.s i may not fully understand certain aspects of javascripting or jquery so please show patients if i ask you to dumb things down abit. thank you