title: writing url to form input value
body: <p><strong>Problem:</strong> I don't know why my script is not loading a value into the selected input section of a form</p>
  
  <p><strong>Scenario:</strong>
  The page, call it the host page, permanently displays a dialog with a link as the content. If a user clicks on the link another dialog, call it the "form dialog" opens with a form. Some items are inserted into the form by the code - platform, browser and url of the host page.</p>
  
  <p>It’s the URL that is not working.</p>
  
  <p>The URL is acquired on the host page and stored as a .data item for recovery by the "form dialog" script.
  I tested this on a simpler set up and it worked perfectly however, it refuses to work on the current set up.</p>
  
  <p><strong>Symptoms:</strong>
  The URL is read and stored as expected but the script is not writing it into the form. The approach I've used is to add a callback function when the dialog is first loaded. The callback uses a .val() function to write the data to the form, or at least that's the intention.
  The value is written to the form during the dialog setup so that when the user clicks the information is already loaded into the form. </p>
  
  <p>I'd appreciate any pointers or suggestions as to what might be the cause of the problem and/or how to correct it.</p>
  
  <p>Thanks.</p>
  
  <p><strong>script:</strong></p>
  
  <pre><code>enter &lt;script type="text/javascript"&gt;
  //Triggers a modal containing the feedback form.
  $(document).ready(function() {
  $('#target a').each(function() {
      var $link = $(this);
      var $dialog = $('&lt;div&gt;&lt;/div&gt;')
          .load($link.attr('href'))
          .dialog({
              autoOpen: false,
              title: $link.attr('title'),
              width: 600,
              height: 500,
              modal:  true,
              open:   function (event,ui) {
                  $("input[name='url']").val($('body').data('value2'));
  
  
              }
          });
  
      $link.click(function() {
          $dialog.dialog('open');
          $( "#accordion" ).accordion({
              collapsible: true,
              active: false
          });
          return false;
      });
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>HOST PAGE</strong></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  &lt;!--Script to get the url of the page and store it as a data item for use on the form --&gt;
  &lt;script type="text/javascript"&gt;
  &lt;?php 
       $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
       ?&gt;
  var pageAddress="&lt;?php echo $url?&gt;";
  
  $('body').data('value2', pageAddress );
  
  &lt;/script&gt;
  &lt;p&gt;The following just confirms that the  url is being stored on the page&lt;/p&gt;
  &lt;div&gt;
  The URL value stored on the page is 
  &lt;span id='urlcheck'&gt;&lt;/span&gt;
  &lt;p&gt;The location is 
  &lt;/p&gt;
  
  &lt;script type="text/javascript"&gt;
  $("span#urlcheck").html("&lt;p&gt;" +$("body").data("value2")+ "&lt;/p&gt;");
  &lt;/script&gt;
  &lt;/div&gt;
  
  
  
  &lt;!--Check to see if the cookie is set --&gt;
  &lt;?php include ('../_assets/include_files/checkreaderStatus.php');?&gt;
  &lt;!-- The following file is for development only. It adds a navigation menu to pages in   which its included. --&gt;
  &lt;?php  include('../_assets/include_files/navigation.html');?&gt;
  &lt;!---------------------------------------------------------------------------&gt;
  &lt;!-- Start The Page Display --&gt;
  &lt;h1&gt;Page 1 Of The Blog&lt;/h1&gt;
  &lt;p&gt;This page simulates the page on the blog where testers will land.&lt;/p&gt;
  
  &lt;!--Dialog for the "Feedback Form Button --&gt;
  &lt;script type="text/javascript"&gt;
  //Reads the flag readerStatus, if set creates a dialog with a permanently displayed "Feedback Button". NOTE TO SELF: This has to be on the page in order for the php to be to be processed by the server!
  var readerStatus="&lt;?php echo $readerStatus; ?&gt;";
  if (readerStatus == "tester") {
      $(function(){
          $("#dialog").dialog();
                  })
  }
  &lt;/script&gt;
  
  &lt;!-- Content for the Feedback Form Button --&gt;   
  &lt;div id="dialog" title="Feedback Button"&gt;
  &lt;div  title="Feedback Form"&gt;
      &lt;p id='target'&gt;&lt;a href="feedbackform.php"  title='Feedback Form' &gt;Feedback   Form&lt;/a&gt;&lt;/p&gt;
      &lt;p class="notes"&gt;This form is dragable and resizable&lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  
  &lt;script type="text/javascript"&gt;
  //Triggers a modal containing the feedback form.
  $(document).ready(function() {
  $('#target a').each(function() {
      var $link = $(this);
      var $dialog = $('&lt;div&gt;&lt;/div&gt;')
          .load($link.attr('href'))
          .dialog({
              autoOpen: false,
              title: $link.attr('title'),
              width: 600,
              height: 500,
              modal:  true,
              open:   function (event,ui) {
                  $("input[name='url']").val($('body').data('value2'));
  
  
              }
          });
  
      $link.click(function() {
          $dialog.dialog('open');
          $( "#accordion" ).accordion({
              collapsible: true,
              active: false
          });
          return false;
      });
  });
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Feedback Form</strong>
      
      
      
      
      Feedback Form
      
      
      
      </p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="../_assets/scripts/black-tie/jquery-ui-1.8.4.custom.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
  
  &lt;?php
  $browser = get_browser(null, true);
  ?&gt;
  &lt;!-- ajax form next? --&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
  var options = {
      target : '#output1',
      url:    'comments.php',
      clearForm:  'true'
  };
  // bind 'myForm' and provide a simple callback function 
  $('#myform').ajaxForm(options);
  return false;
  });
  &lt;/script&gt;
  &lt;!-- Script to execute text prompts in the fields --&gt;
  &lt;!-- optional name --&gt;
  &lt;script type="text/javascript" id="demoscript"&gt;
  $(document).ready(function(){
    //Optionsal Name
      $("#textTagDemo").fieldtag();
    //Textarea
      $("#area").fieldtag();
  });
  &lt;/script&gt;
  
  
  
  
  
  
  
  &lt;div id="accordion"&gt;
  &lt;h3&gt;&lt;a href="#"&gt;Instructions&lt;/a&gt;&lt;/h3&gt;
      &lt;div&gt;
          &lt;p&gt;
          Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
          ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
          amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
          odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
          &lt;/p&gt;
      &lt;/div&gt;
  &lt;h3&gt;&lt;a href="#"&gt;Broken Links&lt;/a&gt;&lt;/h3&gt;
  &lt;div&gt;
  &lt;form action="comments.php" method="post" name="broken_Links" id="myform" &gt;
                  &lt;fieldset&gt;
                      &lt;p&gt;
                          &lt;input name="name" type="text" size="50" id="textTagDemo" title="OPTIONAL: Add your name" /&gt;
  
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;input name="nowhere" type="radio" value="linknowhere" /&gt;Link is
                          broken and doesn't go anywhere
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;input name="wrong_url" type="radio" value="linktowrongurl" /&gt;Link
                          goes to an unexpected destination
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;input name="other" type="radio" value="linkother" /&gt;Other -
                          Please explain in the description box below
                      &lt;/p&gt;
                      &lt;em&gt;Description&lt;/em&gt;
                      &lt;p&gt;Please add as much descripton as you can about the problem you
                          noticed&lt;/p&gt;
                      &lt;textarea name="description" id="area" cols="50" rows="10" title="Please add as much description as you can."&gt;&lt;/textarea&gt;
                      &lt;p&gt;
                          Page Address: &lt;br /&gt; &lt;input name="url" type="text" value=""
                              id="targetURL" size="100" title="Page Address" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          Browser&lt;input name="browser" type="text"
                              value="&lt;?php echo $browser['browser'] ?&gt;" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          Operating System&lt;input name="operating_system" type="text"
                              value="&lt;?php echo $browser['platform'] ?&gt;" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;input type="submit" name="submit" id="button" value="Submit" /&gt;
                      &lt;/p&gt;
                  &lt;/fieldset&gt;
              &lt;/form&gt;
      &lt;!-- server response --&gt;
              &lt;h2&gt;Output Response&lt;/h2&gt;
              &lt;p id="output1"&gt;
  
              &lt;/p&gt;
              &lt;!--End form 4 broken links--&gt;
  &lt;/div&gt;
  &lt;h3&gt;&lt;a href="#"&gt;Errors In The Text&lt;/a&gt;&lt;/h3&gt;
  &lt;div&gt;
      &lt;p&gt;
      Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
      Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
      ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
      lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
      &lt;/p&gt;
      &lt;ul&gt;
          &lt;li&gt;List item one&lt;/li&gt;
          &lt;li&gt;List item two&lt;/li&gt;
          &lt;li&gt;List item three&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  &lt;h3&gt;&lt;a href="#"&gt;Confusing Layout&lt;/a&gt;&lt;/h3&gt;
  &lt;div&gt;
      &lt;p&gt;
      Cras dictum. Pellentesque habitant morbi tristique senectus et netus
      et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
      faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
      mauris vel est.
      &lt;/p&gt;
      &lt;p&gt;
      Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
      Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
      inceptos himenaeos.
      &lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>