How to split a resonce from AJAX accross multiple table cells

trevor1940
trevor1940 used Ask the Experts™
on
Hi

I have a long HTML form part of which one input box contains a Stock_ID when the user types this ID and hits a button an AJAX call GETs a perl script to query a database and if the item exist fills out the Item name, location & 14 other boxes across two rows of the table.

Ive attempted to remove the two rows and replace them with new rows from the perl script but this only adds a new row and keeps the old.

To complicate matters the user is also able to ADD (Infinite) number of Stock_IDs

SO my question is instead of removing and replacing the two table rows How do I split the AJAX response and fill in the existing boxes?

Too Long

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you post some html/javascript code?

Author

Commented:
this code is not compleate the origenal is on an intranet and not easily transferd

is ajaxRequest.ResponceText what perl sends back?

in which case  i'll send back  a text sting like SN=1,A=2,B=3 etc then use javscript todivide it into componats & poulate the oridgenal input boxes rather than replacing them.
Javascript
function invoke(btn)
{
var qs;
var str = btn;
var id2ref = str + "_div";
if (str.substring(0,2)= SN)
  var SN_NO = documentgetElementById(Str).value
  qs = "?SN=" + SN_NO;
 
}
AJAX Stuff here
...
if all OK
 
// where to print
var ajaxDisplay = documentgetElementById(id2ref)
ajaxDisplay.innerHTML='refresh'
ajaxDisplay.innerHTML=ajaxRequest.ResponceText
 
// run query
ajaxRequest.open('GET', 'cgi_bin\test.pl' +qs, true);
ajaxRequest.send(null)
<script>
 
<body>
<form id=MyFom>
<table id=tab1>
       rows be here
</table>
</form>
 
<table id=stock>
     <tr>
         colum b headings
      </tr>    
   <tr>
      <SN1_Div>
          <table>
            <tr>
             <td> <input id =sn type='text'></td>
            <td> <input id =btn1 type='buton' onclick:invooke(SN1></td>
             <16 other td's to be auto filled  over 2 rows>
           <table>
        </div>
</table>
Add row button here
rest of form
Submit button
 
test.pl
use CGI;
use DBI;
my $cgi = new cgi;
my $SN = $cgi->param('SN')
 
connect to db & run sql query
 
test results & send back
either
 
zerro entries
or
 
a completed new SN1_Div 

Open in new window

Assuming that the typos in your code are because you typed this up quickly... (invooke, documentgetElementById, ResponceText)..  Yes ResponseText is what the ajax call has rec eived from the server.

Is the response from the server JSON, XML or CSV string?  If CSV string of values, you can split into an array in javascript using "var a_values = ResponseText.split(",");"

Once you have your values in an array, you can simply change the values of inputs like: "document.getElementById("input_id").value = a_values[2];"

Would need more code/examples to help any further I think..

Author

Commented:
Thanks for your help
I used the arry to loop through the csv string assinging an element id a value

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial