Tab key to create rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    #31
    Error: ajax.req.xmlHtt pReq has no properties

    my getNews.php i have tried to alert the but it is not alerting that
    also if this works
    how do i use it in my dynamic created rows
    and post the values


    all confused

    i have a form wher in i take soem details and then the table creation with one row in which tab key creates required more rows which i have managed with ur code
    but now as u said posting part of all the data above the table as well as the table through ajax



    my getNews file is
    <?
    news_id =$_POST("id");
    $strSQL = "select * from news where news_id = " & new_id;
    $rsdata=mysql_q uery($strSQL);
    echo $rsdata['news_id'];
    ?>


    thanks in advance

    Comment

    • SSG001
      New Member
      • Oct 2007
      • 110

      #32
      [CODE=javascript]
      <html>
      <head>
      <script type="text/javascript">
      function add_row(idx) {
      var table = document.getEle mentById('tbl') ;
      var row = table.getElemen tsByTagName('tr ')[idx];
      var new_row = row.cloneNode(t rue);

      apply_names(tab le, new_row);

      table.getElemen tsByTagName('tb ody')[0].appendChild(ne w_row);
      }

      function apply_names(tab le, row) {
      var inp = row.getElements ByTagName('inpu t');
      var sel = row.getElements ByTagName('sele ct');
      var sfx = table.getElemen tsByTagName('tr ').length;
      var eles = [];
      var ele;

      for (var i = 0; i < inp.length; i++) {
      eles.push(inp[i]);
      }

      for (i = 0; i < sel.length; i++) {
      eles.push(sel[i]);
      }

      for (i = 0; i < eles.length; i++) {
      ele = eles[i];
      ele.setAttribut e('name', ele.getAttribut e('name') + '_' + sfx);
      ele.setAttribut e('id', ele.getAttribut e('id') + '_' + sfx);
      }

      alert(row.inner HTML);
      }

      function add_row_event(e ) {
      var val;

      if (typeof window.event != 'undefined') {
      val = window.event.ke yCode;
      idx = 1;
      } else {
      val = e.keyCode;
      idx = 0;
      }

      if (val == 9) {
      add_row(idx);
      }
      }
      </script>
      </head>
      <body>
      <form method="post">
      <table>
      <tr><td><sele ct name="dept" id="dept">
      <option selected>--- Select depts---</option></select></td></tr>
      <tr><td><sele ct name="study" id="study" >
      <option selected>--- Select studies---</option></select></td></tr>
      <tr><td><inpu t type="text" name="nos" id="nos"></td></tr>
      </table>
      <table id="tbl">
      <thead>
      <th>continent </th>
      <th>country</th>
      <th>longitude </th>
      <th>latitude</th>
      <th>time zone</th>
      </thead>
      <tr>
      <td>
      <select name="mcontinen t" id="mcontinent " tabindex="11">
      <option selected>--- Selectcontinene t ---</option>
      </select>
      </td>
      <td>
      <select name="mcountryc ode" id="mcountrycod e" tabindex="1" >
      <option selected>--- Selectcountry ---</option>
      </select>
      </td>
      <td>
      <input type="text" name="mlong" id="mlong"></td>
      <td>
      <input type="text" name="mlat" id="mlat" ></td>
      <td>
      <input type="text" name="mtime" id="mtime" onkeydown="add_ row_event(event );">
      </td>
      </tr>
      </table>
      <input type="submit" name="submit" value"submit">
      </form>
      </body>
      </html>[/CODE]

      //this is my code ofcourse the selct options are filled from database table values
      and i want to post this data and save
      thanks

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #33
        Originally posted by SSG001
        Error: ajax.req.xmlHtt pReq has no properties
        sorry i overlooked something ... xmlHttpReq is useless, so try this:

        [CODE=javascript]var ajax = function(strURL , sSend, cb) {
        var xmlHttpReq=fals e;

        if (!window.Active XObject) {
        ajax.req = new XMLHttpRequest( );
        } else {
        ajax.req = new ActiveXObject(" Microsoft.XMLHT TP");
        }

        ajax.req.open(' POST', strURL, false);

        ajax.req.setReq uestHeader(
        'Content-Type','applicat ion/x-www-form-urlencoded'
        );

        ajax.req.onread ystatechange = function() {
        if (ajax.req.ready State == 4) {
        cb(ajax.req);
        }
        };

        ajax.req.send(s Send);
        return ajax.req;
        }
        [/CODE]

        Comment

        • SSG001
          New Member
          • Oct 2007
          • 110

          #34
          [CODE=javascript]//set the query string to be sent
          function getquerystring( id) {
          qstr = 'data=' + escape(id); // NOTE: no '?' before querystring
          return qstr;
          }

          //put the data on the page.
          function updatepage(str) {
          document.getEle mentById("data" ).innerHTML = str;
          }
          [/CODE]

          this is not called anywhere in that function
          which actually displays the data
          so my program is nt showing any results


          where am i going wrong?
          and how can i use this in my example
          Last edited by gits; Dec 14 '07, 04:50 PM. Reason: added code tags - please don't forget to use them

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #35
            [CODE=javascript]var ajax = function(strURL , sSend, cb) {
            var xmlHttpReq=fals e;

            if (!window.Active XObject) {
            ajax.req = new XMLHttpRequest( );
            } else {
            ajax.req = new ActiveXObject(" Microsoft.XMLHT TP");
            }

            // here you have to create the right querystring
            var strURL = getquerystring( sSend);

            ajax.req.open(' POST', strURL, false);

            ajax.req.setReq uestHeader(
            'Content-Type','applicat ion/x-www-form-urlencoded'
            );

            ajax.req.onread ystatechange = function() {
            if (ajax.req.ready State == 4) {
            cb(ajax.req);
            }
            };

            ajax.req.send(s Send);
            return ajax.req;
            }
            [/CODE]
            and in your cb you should use:

            [CODE=javascript]var cb = function(res) {
            updatepage(res. responseText);
            };[/CODE]

            Comment

            • SSG001
              New Member
              • Oct 2007
              • 110

              #36
              [HTML]<script type="text/javascript">
              function GetXmlHttpObjec t(){
              var xmlHttp=null;
              try
              {
              xmlHttp=new XMLHttpRequest( );
              }
              catch (e){
              try
              {
              xmlHttp=new ActiveXObject(" Msxml2.XMLHTTP" );
              }
              catch (e)
              {

              xmlHttp=new ActiveXObject(" Microsoft.XMLHT TP");
              }
              }
              if (!xmlHttp && typeof XMLHttpRequest! ='undefined') {
              xmlHttp = new XMLHttpRequest( );
              }
              return xmlHttp;
              }
              function getArticle(id){
              xmlHttp=GetXmlH ttpObject();
              if (xmlHttp==null)
              {
              alert ("Browser does not support HTTP Request");
              return;
              }
              var url="getNews.ph p";
              url=url+"?&news _id="+id;
              url=url+"&sid=" +Math.random();
              alert(url);
              xmlHttp.onready statechange=fun ction(){stateCh anged()} ;
              xmlHttp.open("G ET",url,true) ;
              xmlHttp.send(nu ll);

              }
              function stateChanged()
              {
              if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" )
              {
              document.getEle mentById("data" ).innerHTML=xml Http.responseTe xt;

              }
              }
              </script>
              <form method="GET">
              <select name="news_id" id="news_id" onchange="getAr ticle(this.valu e);">
              <option value="1">-TRain--</option>
              <option value="2">-aerolplane--</option>
              <option value="3">-Car--</option>
              </select>
              <div id="data">VALU E is displayed here </div>
              </form>[/HTML]


              this works fine with me and displays my result also is there any prblem if i use this instead of your code
              now can u tell me how do i use this in my example for posting the value odf dynamic rows as well as as data taken before the table creation

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #37
                as i said some time before ... you simply could call getArticle() from the add_row() method ... but since getArticle() actually receives only one id you should adapt it to your needs ... you would have to retrieve all values of select- and textboxes of a row to build the right query-string for your purpose.

                kind regards

                Comment

                Working...