473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Tab key to create rows

110 100+
Is it possible to create row on client side when tab key is pressed in the last cell of the first row of the table

table is something like this

cell1| cell2| cell3 |cell4| cell5|
____|____|_____|____|____ |_


in the first cell select box is given second select box and remaining columns text boxes
Dec 4 '07 #1
36 2614
gits
5,390 Expert Mod 4TB
hi ...

it should be possible ... please post how you have your first line created, is it a table-row with textboxes?

kind regards
Dec 4 '07 #2
SSG001
110 100+
[HTML]<table id="tbl">
<tr><thead><th>continent</th><th>country</th> <th>longitude</th>
<th>latitude</th>
<th>time zone</th>
</thead> </tr>
<td><select name="mcontinent" id="mcontinent" tabindex="11">
<option selected>--- Selectcontinenet ---</option>
//shown from continenet master
</select></td>

<tr> <td><select name="mcountrycode" id="mcountrycode" tabindex="1" >
<option selected>--- Selectcountry ---</option>
//option selected from country master table
</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" ></td>
</tr>
</table>[/HTML]
Dec 7 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

have a look at the following example:

[HTML]<script type="text/javascript">
function add_row() {
var table = document.getElementById('tbl');
var row = table.getElementsByTagName('tr')[0];
var new_row = row.cloneNode(true);

table.appendChild(new_row);
}

function add_row_event(e) {
var val = typeof window.event != 'undefined' ? window.event.keyCode : e.keyCode;

if (val == 9) {
add_row();
}
}
</script>

<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="mcontinent" id="mcontinent" tabindex="11">
<option selected>--- Selectcontinenet ---</option>
</select>
</td>
<td>
<select name="mcountrycode" id="mcountrycode" 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" onkeypress="add_row_event(event);">
</td>
</tr>
</table>
[/HTML]
kind regards
Dec 8 '07 #4
SSG001
110 100+
Thanks
this works
prefectly in mozilla bt not in IE 6 it doesnt append any row
and how do i name the rows coulmns created in the array
something like
<input type="text" name="mlong[i]" id="mlong[i]"></td>
Dec 10 '07 #5
gits
5,390 Expert Mod 4TB
first ... small adaptation to make it work with IE, it seems that that silly IE don't fire onkeypress with tab-key ... so we use the keydown-event. next we need to use to append to the tbody and we have to use tr with idx 1 instead. here is the script:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function add_row(idx) {
  3.     var table   = document.getElementById('tbl');
  4.     var row     = table.getElementsByTagName('tr')[idx];
  5.     var new_row = row.cloneNode(true);
  6.  
  7.     table.getElementsByTagName('tbody')[0].appendChild(new_row);
  8. }
  9.  
  10. function add_row_event(e) {
  11.     var val;
  12.  
  13.     if (typeof window.event != 'undefined') {
  14.         val = window.event.keyCode;
  15.         idx = 1;
  16.     } else {
  17.         val = e.keyCode;
  18.         idx = 0;
  19.     }
  20.  
  21.     if (val == 9) {
  22.         add_row(idx);
  23.     }
  24. }
  25. </script>
  26.  
  27. <table id="tbl">
  28.     <thead>
  29.         <th>continent</th>
  30.         <th>country</th>
  31.         <th>longitude</th>
  32.         <th>latitude</th>
  33.         <th>time zone</th>
  34.     </thead>
  35.     <tr>
  36.         <td>
  37.             <select name="mcontinent" id="mcontinent"  tabindex="11">
  38.                 <option selected>--- Selectcontinenet ---</option>
  39.             </select>
  40.         </td>
  41.         <td>
  42.             <select name="mcountrycode" id="mcountrycode" tabindex="1" >
  43.                 <option selected>--- Selectcountry ---</option>
  44.             </select>
  45.         </td>
  46.         <td>
  47.             <input type="text" name="mlong" id="mlong"></td>
  48.         <td>
  49.             <input type="text" name="mlat" id="mlat" ></td>
  50.         <td>
  51.             <input type="text" name="mtime" id="mtime" onkeydown="add_row_event(event);">
  52.         </td>
  53.     </tr>
  54. </table>
  55.  
kind regards
Dec 10 '07 #6
gits
5,390 Expert Mod 4TB
...
and how do i name the rows coulmns created in the array
something like
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="mlong[i]" id="mlong[i]">
  2.  
therefore you have to loop through the cloned row's child elements and assign your desired id and name to the input before appending it to the table ...

kind regards
Dec 10 '07 #7
SSG001
110 100+
is it somwething like this
Expand|Select|Wrap|Line Numbers
  1.      for (i=0;i<=5;i++){
  2.              tdObj = document.createElement("td")[i];
  3.  
  4.     }
  5.  
but how i append it to the row
Dec 11 '07 #8
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1.     var cells = new_row.childNodes;
  2.     for (var i=0;i<cells.length;i++) {
  3.     var cellName = cells[i].name;
  4.     var cellid=cells[i].id;
  5.         if (cellName){
  6.             cells[i].name =cellName + "["+i+"]";
  7.             cells[i].id=cellName+"["+i+"]";
  8. alert(cells[i].name);
  9.         }
  10.  
  11.     }

//but it not alerting anything to see if the naming is proper
Dec 11 '07 #9
gits
5,390 Expert Mod 4TB
hmmm ... do you want something like this?

[HTML]<script type="text/javascript">
function add_row(idx) {
var table = document.getElementById('tbl');
var row = table.getElementsByTagName('tr')[idx];
var new_row = row.cloneNode(true);

apply_names(table, new_row);

table.getElementsByTagName('tbody')[0].appendChild(new_row);
}

function apply_names(table, row) {
var inp = row.getElementsByTagName('input');
var sel = row.getElementsByTagName('select');
var sfx = table.getElementsByTagName('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.setAttribute('name', ele.getAttribute('name') + '_' + sfx);
ele.setAttribute('id', ele.getAttribute('id') + '_' + sfx);
}

alert(row.innerHTML);
}

function add_row_event(e) {
var val;

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

if (val == 9) {
add_row(idx);
}
}
</script>

<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="mcontinent" id="mcontinent" tabindex="11">
<option selected>--- Selectcontinenet ---</option>
</select>
</td>
<td>
<select name="mcountrycode" id="mcountrycode" 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>
[/HTML]
kind regards
Dec 11 '07 #10
SSG001
110 100+
looks like it's same


Thanks a lot
Dec 11 '07 #11
gits
5,390 Expert Mod 4TB
hi ...

the same as what? :) ... its different because your code tried to set the name/id of table-cells ... the above one sets it for the input-elements ...

kind regards
Dec 11 '07 #12
SSG001
110 100+
Hi
mean to say this is what i wanted

thanks
Dec 11 '07 #13
gits
5,390 Expert Mod 4TB
ahhh ... i see ... ;) ... do you want to post the form later on to a serverside script?
Dec 11 '07 #14
arunj82
15
hi ...

I am new to Javascript. Could you please help me how to create a new row by clicking the image or any text link. I tried the above code but the add row message comes after every row. This is my same example code
Expand|Select|Wrap|Line Numbers
  1.       <script type="text/javascript">
  2.       function add_row(idx) {
  3.           var table   = document.getElementById('tbl');
  4.           var row     = table.getElementsByTagName('tr')[idx];
  5.           var new_row = row.cloneNode(true);
  6.           table.getElementsByTagName('tbody')[0].appendChild(new_row);
  7.       }
  8.  
  9.       function add_row_event(e) {
  10.       var val;
  11.       if (typeof window.event != 'undefined') {
  12.             val = window.event.keyCode;
  13.             idx = 1;
  14.           } else {
  15.               val = e.keyCode;
  16.               idx = 0;
  17.           }
  18.           if (val == 0) {
  19.               add_row(idx);
  20.           }
  21.       }
  22.       </script>
  23.       <table id="tbl">
  24.           <thead>
  25.               <th>longitude</th>
  26.               <th>latitude</th>
  27.               <th>time zone</th>
  28.          </thead>
  29.           <tr>
  30.               <td>
  31.                   <input type="text" name="mlong" id="mlong"></td>
  32.               <td>
  33.                     <input type="text" name="mlat" id="mlat" ></td>
  34.               <td>    
  35.                  <input type="text" name="mtime" id="mtime">
  36.               </td>
  37.               <td>&nbsp;&nbsp;<a href="#" onClick="add_row_event(event);">Add Row</a> </td>
  38.           </tr>
  39.       </table>
Dec 11 '07 #15
SSG001
110 100+
yes right
have to actually post the data using to server side using php
Dec 11 '07 #16
gits
5,390 Expert Mod 4TB
in that case we have to adapt the script ... because think i remember that IE makes problems when setting name attribs during runtime ... could you try to post the form and have a look whether it works for you at the moment or not?

kind regards
Dec 11 '07 #17
SSG001
110 100+
[PHP]//count value shows 1 although i created three rows
<?
if($_POST['submit']){
$ct=count($_POST['mcontinent']);
?> <script>alert('<?=$ct?>');</script> <?
}
?>
<html>
<head>
<script type="text/javascript">
function add_row(idx) {
var table = document.getElementById('tbl');
var row = table.getElementsByTagName('tr')[idx];
var new_row = row.cloneNode(true);

apply_names(table, new_row);

table.getElementsByTagName('tbody')[0].appendChild(new_row);
}

function apply_names(table, row) {
var inp = row.getElementsByTagName('input');
var sel = row.getElementsByTagName('select');
var sfx = table.getElementsByTagName('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.setAttribute('name', ele.getAttribute('name') + '_' + sfx);
ele.setAttribute('id', ele.getAttribute('id') + '_' + sfx);
}

alert(row.innerHTML);
}

function add_row_event(e) {
var val;

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

if (val == 9) {
add_row(idx);
}
}
</script>
</head>
<body>
<form method="post">
<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="mcontinent" id="mcontinent" tabindex="11">
<option selected>--- Selectcontinenet ---</option>
</select>
</td>
<td>
<select name="mcountrycode" id="mcountrycode" 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>[/PHP]
Dec 12 '07 #18
gits
5,390 Expert Mod 4TB
:) sorry in case i didn't make myself very clear ... we create new rows in the table at the client ... that table contains input-nodes where we set the name dynamically ... after the user filled in some values ... the question is now: should that form be posted back to the server without using ajax? in case it should be simply posted back then we have to consider the following IE-'bug' :) here that means that IE doesn't allow to set the name-attribute at runtime so when posting the form you might miss the variable-names of the posted form-parameters and we may use something like this to work around that problem

kind regards
Dec 12 '07 #19
SSG001
110 100+
As u see there are two select boxes in the row
so evrytime i'll have to refresh page
so i have read somewhere it can be avoided with ajax
also if we do the posting of this data through ajax then how to go about



thanks
Dec 12 '07 #20
gits
5,390 Expert Mod 4TB
in that case you may create the querystring for the ajax-request for youself out of the lines or use the node-ids ... so we wouldn't have the name-problem here :) ...

are you familiar with ajax and how it works?

kind regards
Dec 12 '07 #21
SSG001
110 100+
have read lot of theory but no practicals
can u just show me with only one field posting with ajax
Dec 12 '07 #22
gits
5,390 Expert Mod 4TB
hi ...

here you find an example

kind regards
Dec 12 '07 #23
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. //set the variables.
  3. function getArticle(id) {
  4.     var cb = function(res) {
  5.         alert(res.responseText);
  6.     };
  7.  
  8.     ajax('getNews.php', id,cb);
  9. }
  10.  
  11. //Make the actual connection.
  12. ajax = function(strURL, sSend) {
  13.     var xmlHttpReq=false;
  14.  
  15.     if (!window.ActiveXObject) ajax.req = new XMLHttpRequest();
  16.     else ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  17.  
  18.     ajax.req.open('POST',strURL,false);
  19.     ajax.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  20.  
  21.     ajax.req.send(sSend);
  22.     return ajax.req;
  23. }
  24.  
  25.  
  26. //set the query string to be sent
  27. function getquerystring(id) {
  28.     qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
  29.     return qstr;
  30. }
  31.  
  32. //put the data on the page.
  33. function updatepage(str) {
  34.     document.getElementById("data").innerHTML = str;
  35. }
  36. </script>
  37. <select onchange="getArticle(this.value);">
  38. <option value="1">Train</option>
  39. <option value="2">Airplane Crashes</option>
  40. <option value="3">Mental Health</option>
  41. </select>
  42. <div id="data"></div>

[PHP]<?
news_id = request("id")
$strSQL = "select * from news where news_id = " & new_id
$rsdata=mysql_query($strSQL);
echo $rsdata['news_id'];
?>[/PHP]

//is this example will work with IE,mozilla
Dec 13 '07 #24
gits
5,390 Expert Mod 4TB
hi ...

that code should not work ... or is it? the problem is with the cb you don't have it assigned to the onreadystatechange of the XMLHttpRequest-object ...

kind regards
Dec 13 '07 #25
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. //set the variables.
  3. function getArticle(id) {
  4.     var cb = function(res) {
  5.         alert(res.responseText);
  6.     };
  7.  
  8.     ajax('getNews.php', id,cb);
  9. }
  10.  
  11. //Make the actual connection.
  12. ajax = function(strURL, sSend) {
  13.     var xmlHttpReq=false;
  14.  
  15.     if (!window.ActiveXObject) ajax.req = new XMLHttpRequest();
  16.     else ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  17.  
  18.     ajax.req.open('POST',strURL,false);
  19.     ajax.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  20. ajax.req.xmlHttpReq.onreadystatechange = function(cb) {
  21.         if (ajax.req.xmlHttpReq.readyState == 4) {
  22.             cb(ajax.req.xmlHttpReq);
  23.         }
  24.  
  25.  
  26.     ajax.req.send(sSend);
  27.     return ajax.req;
  28. }
  29.  
  30.  
  31. //set the query string to be sent
  32. function getquerystring(id) {
  33.     qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
  34.     return qstr;
  35. }
  36.  
  37. //put the data on the page.
  38. function updatepage(str) {
  39.     document.getElementById("data").innerHTML = str;
  40. }
  41. </script>
  42. <select onchange="getArticle(this.value);">
  43. <option value="1">Train</option>
  44. <option value="2">Airplane Crashes</option>
  45. <option value="3">Mental Health</option>
  46. </select>
  47. <div id="data"></div>


Code: ( php )
Expand|Select|Wrap|Line Numbers
  1. <?
  2. news_id = request("id")
  3. $strSQL = "select * from news where news_id = " & new_id
  4. $rsdata=mysql_query($strSQL);
  5. echo $rsdata['news_id'];
  6. ?>

will this give me names of the rows properly for posting
Dec 13 '07 #26
SSG001
110 100+
i have used ajax for posting data from tables created using add row button
but not with tab key.
and the creation of rows was also using createElement method and then appending
the naming is also done for each row and each cell
but this tab key method looks more sleek then clicking button for adding row
how do i post the data from the rows created to server using ajax
Dec 14 '07 #27
gits
5,390 Expert Mod 4TB
your ajax-request is working? ... i wonder because you should have to receive the cb in your ajax-function like this:

Expand|Select|Wrap|Line Numbers
  1. var ajax = function(strURL, sSend, cb) {
  2.     // your code here
  3.     // and later on you simply could use it:
  4.  
  5.     ajax.req.xmlHttpReq.onreadystatechange = cb;
  6.  
  7.     // your further code here :)
  8. }
you could call getArticle it from our add_row-function ... to have it called on tab-press ...

kind regards
Dec 14 '07 #28
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. //set the variables.
  3. function getArticle(id) {
  4.     var cb = function(res) {
  5.         alert(res.responseText);
  6.     };
  7.  
  8.     ajax('getNews.php', id,cb);
  9. }
  10.  
  11. //Make the actual connection.
  12.  
  13.  
  14.  
  15. var ajax = function(strURL, sSend,cb) {
  16.     var xmlHttpReq=false;
  17.  
  18.     if (!window.ActiveXObject) ajax.req = new XMLHttpRequest();
  19.     else ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  20.  
  21.     ajax.req.open('POST',strURL,false);
  22.     ajax.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  23.     ajax.req.xmlHttpReq.onreadystatechange = cb;
  24.         if (ajax.req.xmlHttpReq.readyState == 4) {
  25.             cb(ajax.req.xmlHttpReq);
  26.         }
  27.  
  28.  
  29.     ajax.req.send(sSend);
  30.     return ajax.req;
  31. }
  32.  
  33.  
  34. //set the query string to be sent
  35. function getquerystring(id) {
  36.     qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
  37.     return qstr;
  38. }
  39.  
  40. //put the data on the page.
  41. function updatepage(str) {
  42.     document.getElementById("data").innerHTML = str;
  43. }
  44. </script>
  45. <select onchange="getArticle(this.value);">
  46. <option value="1">Train</option>
  47. <option value="2">Airplane Crashes</option>
  48. <option value="3">Mental Health</option>
  49. </select>
  50. <div id="data"></div>

//here the updatepage is not cakled anywhere which displays the str
also how do i use this in my example
i have used ajax earlier but as i said different way of cross browser creation
and even the rows creation was using button as i have mentioned
not with tab key
can u just show me how to use it in my example
i also have some select box and text box vales above the table which is created dynamically
Dec 14 '07 #29
gits
5,390 Expert Mod 4TB
hi ...

the following code should work now ...
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. //set the variables.
  3. function getArticle(id) {
  4.     var cb = function(res) {
  5.         alert(res.responseText);
  6.     };
  7.  
  8.     ajax('getNews.php', id,cb);
  9. }
  10.  
  11. //Make the actual connection.
  12. var ajax = function(strURL, sSend, cb) {
  13.     var xmlHttpReq=false;
  14.  
  15.     if (!window.ActiveXObject) {
  16.         ajax.req = new XMLHttpRequest();
  17.     } else {
  18.         ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  19.     }
  20.  
  21.     ajax.req.open('POST', strURL, false);
  22.  
  23.     ajax.req.setRequestHeader(
  24.         'Content-Type','application/x-www-form-urlencoded'
  25.     );
  26.  
  27.     ajax.req.xmlHttpReq.onreadystatechange = function() {
  28.         if (ajax.req.xmlHttpReq.readyState == 4) {
  29.             cb(ajax.req.xmlHttpReq);
  30.         }
  31.     };
  32.  
  33.     ajax.req.send(sSend);
  34.     return ajax.req;
  35. }
  36.  
  37. //set the query string to be sent
  38. function getquerystring(id) {
  39.     qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
  40.     return qstr;
  41. }
  42.  
  43. //put the data on the page.
  44. function updatepage(str) {
  45.     document.getElementById("data").innerHTML = str;
  46. }
  47. </script>
  48. <select onchange="getArticle(this.value);">
  49. <option value="1">Train</option>
  50. <option value="2">Airplane Crashes</option>
  51. <option value="3">Mental Health</option>
  52. </select>
  53. <div id="data"></div>
to your next step: could you summarize what your page looks like and what you want to do now exactly?

kind regards
Dec 14 '07 #30
SSG001
110 100+
Error: ajax.req.xmlHttpReq 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_query($strSQL);
echo $rsdata['news_id'];
?>


thanks in advance
Dec 14 '07 #31
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function add_row(idx) {
  5.     var table   = document.getElementById('tbl');
  6.     var row     = table.getElementsByTagName('tr')[idx];
  7.     var new_row = row.cloneNode(true);
  8.  
  9.     apply_names(table, new_row);
  10.  
  11.     table.getElementsByTagName('tbody')[0].appendChild(new_row);
  12. }
  13.  
  14. function apply_names(table, row) {
  15.     var inp  = row.getElementsByTagName('input');
  16.     var sel  = row.getElementsByTagName('select');
  17.     var sfx  = table.getElementsByTagName('tr').length;
  18.     var eles = [];
  19.     var ele;
  20.  
  21.     for (var i = 0; i < inp.length; i++) {
  22.         eles.push(inp[i]);
  23.     }
  24.  
  25.     for (i = 0; i < sel.length; i++) {
  26.         eles.push(sel[i]);
  27.     }
  28.  
  29.     for (i = 0; i < eles.length; i++) {
  30.         ele = eles[i];
  31.         ele.setAttribute('name', ele.getAttribute('name') + '_' + sfx);
  32.         ele.setAttribute('id', ele.getAttribute('id') + '_' + sfx);
  33.     }
  34.  
  35.     alert(row.innerHTML);
  36. }
  37.  
  38. function add_row_event(e) {
  39.     var val;
  40.  
  41.     if (typeof window.event != 'undefined') {
  42.         val = window.event.keyCode;
  43.         idx = 1;
  44.     } else {
  45.         val = e.keyCode;
  46.         idx = 0;
  47.     }
  48.  
  49.     if (val == 9) {
  50.         add_row(idx);
  51.     }
  52. }
  53. </script>
  54. </head>
  55.  <body>
  56.  <form method="post">
  57. <table>
  58. <tr><td><select name="dept" id="dept">
  59.     <option selected>--- Select depts---</option></select></td></tr>
  60. <tr><td><select name="study" id="study" >
  61.   <option selected>--- Select studies---</option></select></td></tr>
  62. <tr><td><input type="text" name="nos" id="nos"></td></tr>
  63. </table>
  64. <table id="tbl">
  65.     <thead>
  66.         <th>continent</th>
  67.         <th>country</th>
  68.         <th>longitude</th>
  69.         <th>latitude</th>
  70.         <th>time zone</th>
  71.     </thead>
  72.     <tr>
  73.         <td>
  74.             <select name="mcontinent" id="mcontinent"  tabindex="11">
  75.                 <option selected>--- Selectcontinenet ---</option>
  76.             </select>
  77.         </td>
  78.         <td>
  79.             <select name="mcountrycode" id="mcountrycode" tabindex="1" >
  80.                 <option selected>--- Selectcountry ---</option>
  81.             </select>
  82.         </td>
  83.         <td>
  84.             <input type="text" name="mlong" id="mlong"></td>
  85.         <td>
  86.             <input type="text" name="mlat" id="mlat" ></td>
  87.         <td>
  88.             <input type="text" name="mtime" id="mtime" onkeydown="add_row_event(event);">
  89.         </td>
  90.     </tr>
  91. </table>
  92. <input type="submit" name="submit" value"submit">
  93. </form>
  94. </body>
  95. </html>
//this is my code ofcourse the selct options are filled from database table values
and i want to post this data and save
thanks
Dec 14 '07 #32
gits
5,390 Expert Mod 4TB
Error: ajax.req.xmlHttpReq has no properties
sorry i overlooked something ... xmlHttpReq is useless, so try this:

Expand|Select|Wrap|Line Numbers
  1. var ajax = function(strURL, sSend, cb) {
  2.     var xmlHttpReq=false;
  3.  
  4.     if (!window.ActiveXObject) {
  5.         ajax.req = new XMLHttpRequest();
  6.     } else {
  7.         ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }
  9.  
  10.     ajax.req.open('POST', strURL, false);
  11.  
  12.     ajax.req.setRequestHeader(
  13.         'Content-Type','application/x-www-form-urlencoded'
  14.     );
  15.  
  16.     ajax.req.onreadystatechange = function() {
  17.         if (ajax.req.readyState == 4) {
  18.             cb(ajax.req);
  19.         }
  20.     };
  21.  
  22.     ajax.req.send(sSend);
  23.     return ajax.req;
  24. }
  25.  
Dec 14 '07 #33
SSG001
110 100+
Expand|Select|Wrap|Line Numbers
  1. //set the query string to be sent
  2. function getquerystring(id) {
  3.     qstr = 'data=' + escape(id);  // NOTE: no '?' before querystring
  4.     return qstr;
  5. }
  6.  
  7. //put the data on the page.
  8. function updatepage(str) {
  9.     document.getElementById("data").innerHTML = str;
  10. }
  11.  
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
Dec 14 '07 #34
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. var ajax = function(strURL, sSend, cb) {
  2.     var xmlHttpReq=false;
  3.  
  4.     if (!window.ActiveXObject) {
  5.         ajax.req = new XMLHttpRequest();
  6.     } else {
  7.         ajax.req = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }
  9.  
  10.     // here you have to create the right querystring
  11.     var strURL = getquerystring(sSend);
  12.  
  13.     ajax.req.open('POST', strURL, false);
  14.  
  15.     ajax.req.setRequestHeader(
  16.         'Content-Type','application/x-www-form-urlencoded'
  17.     );
  18.  
  19.     ajax.req.onreadystatechange = function() {
  20.         if (ajax.req.readyState == 4) {
  21.             cb(ajax.req);
  22.         }
  23.     };
  24.  
  25.     ajax.req.send(sSend);
  26.     return ajax.req;
  27. }
  28.  
and in your cb you should use:

Expand|Select|Wrap|Line Numbers
  1. var cb = function(res) {
  2.     updatepage(res.responseText);
  3. };
Dec 14 '07 #35
SSG001
110 100+
[HTML]<script type="text/javascript">
function GetXmlHttpObject(){
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
function getArticle(id){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="getNews.php";
url=url+"?&news_id="+id;
url=url+"&sid="+Math.random();
alert(url);
xmlHttp.onreadystatechange=function(){stateChanged ()} ;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("data").innerHTML=xmlHttp. responseText;

}
}
</script>
<form method="GET">
<select name="news_id" id="news_id" onchange="getArticle(this.value);">
<option value="1">-TRain--</option>
<option value="2">-aerolplane--</option>
<option value="3">-Car--</option>
</select>
<div id="data">VALUE 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
Dec 15 '07 #36
gits
5,390 Expert Mod 4TB
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
Dec 15 '07 #37

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: kackson | last post by:
Hi. I created a simple view with the following statements: CREATE VIEW dbo.VIEW1 AS SELECT dbo.VIEW_ALL.ID, dbo.VIEW_ALL.Code, Another.dbo.OTHER_VIEW.Label as SpecialCode FROM ...
7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
11
by: dfurtney | last post by:
SQL Server 7/2000: We have reasonably large tables (3,000,000 rows) that we need to add some indexes for. In a test, it took over 12 hours to CREATE a new INDEX against this table. One of us...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: kennedystephen | last post by:
This seems like a simple task. But it's kicking my butt. I have 1 existing excel file. I want to copy the first 50 rows from that excel file, and put them in a new excel file. Then I want to get...
0
by: kennedystephen | last post by:
For the life of me, I cannot get this ... I have 1 excel document. I want to open that document and copy the first 50 rows to a new document. Then get the next 50 rows and copy those to a brand...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.