Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 1.76 KB  |  views: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2.     <head>
  3.         <title></title>
  4.         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  5.         <script type="text/javascript">
  6.             $(document).ready(function () {
  7.  
  8.                 var dataSet = $("#container").remove(); // just grab the data. could have also types it all on one line, same thing
  9.  
  10.                 alert("dataSet: " + dataSet.html());                               // nothing in my hands
  11.                 alert("body: (should just be a comment)" + $("body").html());      // nothing up my sleeves
  12.  
  13.                 var fields = ["email", "phone"];                                    // targets
  14.                 for (var i = 0; i < fields.length; i++) {                           // foreach...
  15.                     dataSet.find("[name='" + fields[i] + "']").val("Hello World");  // target change the val
  16.                     alert("worked here: " + dataSet.find("[name='" + fields[i] + "']").val());   // great! it changed the val
  17.                     alert("but not here: " + dataSet.html()); // except it didnt.
  18.                 }
  19.                 dataSet.html("***");  // yet this works,        
  20.                 alert("yet works this way" + dataSet.html());                                  
  21.             });
  22.         </script>
  23.     </head>
  24.     <body>
  25.  
  26.     <!-- Just here to get this into memory-->
  27.     <div id="container">
  28.         <div>
  29.                 <label for="email">eMail</label>
  30.                 <input type="text" name="email" value="this.doesnt@work.com" id="eMail" disabled="">
  31.         </div>
  32.         <div>
  33.                 <label for="phone" >phone</label>
  34.                 <input type="text" name="phone" value="(555) 800-1212" id="phone" disabled="">
  35.         </div>
  36.     </div>
  37.     </body>
  38. </html>
clone this paste RAW Paste Data