Reply to Re: Returning an array from javascript to php variable

Your name:

Reply:


Posted by Chung Leong on 10/11/14 11:36

Srinivas Aki wrote:
> Hello Everyone,
> I'm trying to read a dynamic table into an array and then return it
> back to the php array so that I can register that for the session. I'm
> not too sure if i'm going in the right direction though. Javascript
> follows.
>
> function get_ticket_cart(){
> var tamt = document.getElementById('tamt');
> var tcells = tamt.cells;
> var total = tcells[tcells.length-1];
> return tcells;
> }
>
> And I'm trying to do this on onClick of the form. Php code follows
>
> $tickets = array();
> <input type="submit" value="Pay Dues" onclick="<? $tickets ?> =
> get_ticket_cart();" >
>
> $_SESSION['tickets'] = $tickets;
> session_register('tickets');
>
> I could be wrong in trying to catch the return value. But the problem
> is this needs to be done on the click event.
>
> Any suggestions are appreciated.
>
> Thanks
> saki

Well, since the table is dynamically generated, there obviously is a
time when you're in possession of the data that populates it. Why not
just add this data to a hidden field at time the same time as you're
generating a new row? Personally, I like to just keep the data in an
array, then redraw the whole table every time it changes. Makes it
easier when you need to remove an item.

Example:

var tickets = Array();

function add_ticket(id) {
tickets.push(id);
refresh_table();
save_to_hidden();
}

function refresh_table() {
var html = '';
for(var i = 0; i < tickets.length; i++) {
html += '<html here>';
}
table.innerHTML = html;
}

function save_to_hidden() {
hidden.value = tickets.join(',', tickets);
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация