Advertisement
Guest User

Untitled

a guest
Aug 8th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.12 KB | None | 0 0
  1. <script src="jquery-1.10.2.js"></script>
  2. <script language="JavaScript">
  3. function get_XmlHttp() {
  4.   // create the variable that will contain the instance of the XMLHttpRequest object (initially with null value)
  5.   var xmlHttp = null;
  6.  
  7.   if(window.XMLHttpRequest) {   // for Forefox, IE7+, Opera, Safari, ...
  8.     xmlHttp = new XMLHttpRequest();
  9.   }
  10.   else if(window.ActiveXObject) { // for Internet Explorer 5 or 6
  11.     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  12.   }
  13.  
  14.   return xmlHttp;
  15. }
  16.  
  17. // sends data to a php file, via GET and POST, and displays the received answer
  18. function ajaxrequest(php_file, tagID) {
  19.   var request =  get_XmlHttp();        // call the function for the XMLHttpRequest instance
  20.  
  21.   // create pairs index=value with data that must be sent to server, via POST
  22.   var  d_post = 'content='+document.getElementById('broadcast').value+'&submit=1'+'&enable_text='+document.getElementById('enable_text').value+'&status='+document.getElementById('status').value;
  23.   //var  d_post = 'submit='+document.getElementById('submit').value+'&content='+document.getElementById('content').value+'&status='+document.getElementById('status').value+'&enable_text='+document.getElementById('enable_text').value;
  24.   request.open("POST", "list.php", true);      // sets the request
  25.  
  26.   // adds  a header to tell the PHP script to recognize the data as is sent via POST
  27.   request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  28.   request.send(d_post);       // sends the request
  29.  
  30.   // Check request status
  31.   // If the response is received completely, will be transferred to the HTML tag with tagID
  32.   request.onreadystatechange = function() {
  33.     if (request.readyState == 4) {
  34.       document.getElementById('list').innerHTML = request.responseText;
  35.     }
  36.   }
  37. }
  38.  
  39. function toggle(source)
  40. {
  41.     checkboxes = document.getElementsByName('option[]');
  42.     for(var i=0, n=checkboxes.length;i<n;i++)
  43.     {
  44.         checkboxes[i].checked = source.checked;
  45.     }
  46. }
  47.  
  48. function toggleDisabled(_checked)
  49. {
  50.     document.getElementById('broadcast').disabled = _checked ? false : true;
  51. }
  52. </script>
  53.             <table>
  54.                 <tr>
  55.                     <th><input type="checkbox" onClick="toggle(this)" /></th>
  56.                     <th>test</th>
  57.                     <th>test</th>
  58.                     <th>test</th>
  59.                 </tr>
  60.             </table>
  61. <div id="list"></div>
  62.  
  63.             <form action="list.php" method="post" name="form2" onsubmit="ajaxrequest('list.php', 'content'); return false;">
  64.             <p>Texte:
  65.             <input type="checkbox" id="enable_text" name="enable_text" onchange="toggleDisabled(this.checked)"/>
  66.             Status:
  67.             <select name="status" id="status">
  68.                 <option VALUE="waiting" selected="selected"> en attente</option>
  69.                 <option VALUE="solved"> résolu</option>
  70.                 <option VALUE="closed"> clos</option>
  71.             </select>
  72.             <input id="submit" type="submit" value="Send" />
  73.             </p>
  74.             <textarea disabled id="broadcast" name="content" rows="4" cols="80"></textarea>
  75.             </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement