0

I have been working on this for hours, and I haven't been able to get it right.

I am using jquery to pull <address> from an xml file. From there, I am using it to set that value to that of the hidden input. And from there, I would like to send the hmtl data to the .php file. I have tried everything I can think of and now it's 5:23AM.

Here is my HTML <input type="hidden" id="SenatorAddress" name="SA" />

Here is the JS: `

     {

        $('#StateSelect').change(function(){
            $('#SenatorSelect').empty();
            var state = $(this).val();
            var select1 = $('#SenatorSelect');
            var SAD = $('#SenatorAddress');
            select1.append('<option value="Select a senator">Select a Senator</option>');
        $(xml).find('member').each(function(){
            if(state == $(this).find('state').text()){
            var fname = $(this).find('first_name').text();
            var lname = $(this).find('last_name').text();
            select1.append("<option>"+fname+"&nbsp"+lname+"</option>");
            var sadress = $(this).find('address').text();
             SAD.append(Sadress);
        }

Here is the PHP:

The Honorable <?php echo $_GET["senatornames"]; ?><br>
<?php echo $_GET["SA"]; ?><br>
United States Senate<br />
Washington, DC 20510<br />
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
mousadafousa
  • 77
  • 4
  • 14
  • I don't see `$('#StateSelect').change(function()` bind to any element, either post complete code n if this is all then check the `var` like set `alert(state);` and see if you get alerts – Shehary Jun 30 '15 at 09:37
  • That is all the code – mousadafousa Jun 30 '15 at 09:45
  • Did you get alert, you can check all `var` by setting alert and see whats going wrong at which point. – Shehary Jun 30 '15 at 09:55
  • I tried but I didn't get an alert. I just wrote alert(sadress); under it though. – mousadafousa Jun 30 '15 at 10:01
  • that means nothing is there, check all var from top to bottom. start from `alert(state);`, `alert(select1);` onwards and if you don't get any alert at all, means your change function not working, where i can see its not bind to any element. – Shehary Jun 30 '15 at 10:04
  • I see what you mean. I am running a website. Would the alert come as I ran the website? – mousadafousa Jun 30 '15 at 10:07
  • No, the alert only triggers with `$('#StateSelect').change(function()`, also check your browser console for error. – Shehary Jun 30 '15 at 10:08
  • Wow. It works now. I want to thank you both extensively for showing me a new tool that I can check my code with. I'm beyond appreciative. – mousadafousa Jun 30 '15 at 10:10
  • Glad to be of any help. – Shehary Jun 30 '15 at 10:18

1 Answers1

0

Use SAD.val(sadress) instead of SAD.append(Sadress);

ash__939
  • 1,614
  • 2
  • 12
  • 21
  • what is the output of alert(sadress); – ash__939 Jun 30 '15 at 09:55
  • I did not get an alert. Would the alert appear as I ran the $(#SenateSelect).change function? – mousadafousa Jun 30 '15 at 10:04
  • Post you full script. It's very difficult to check it with the partial code. From what I can understand from this, an alert should be shown if the there is an entry for the selected state in the xml . – ash__939 Jun 30 '15 at 10:07
  • as a checking you can try omitting if(state == $(this).find('state').text()){ checking from you script. It should then show an alert for each "member" in the xml. If it shows then check the alert(state ) to see whether its being set. If yes then check the xml for the existence of sadressthat matches the selected state value. SAD.val(sadress) should work if you can find sadress for the selected state. – ash__939 Jun 30 '15 at 10:11
  • Your .valc() suggestion actually worked! It was an error on my part. Thank you very much. – mousadafousa Jun 30 '15 at 10:16