Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 974 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Passing an array from PHP to Javascript

Thread title: Passing an array from PHP to Javascript
Closed Thread    
    Thread tools Search this thread Display Modes  
09-16-2008, 02:17 PM
#1
dele454 is offline dele454
dele454's Avatar
Status: I'm new around here
Join date: Sep 2008
Location: cape town, south africa
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

dele454 is on a distinguished road

  Old  Passing an array from PHP to Javascript



hi,

i am not a js guru so pls permit my naiveness. I need the 'delete' button on the highlighted graphic to delete all checked pics for delete. My view has the checkboxes as an array so i need to pass this array to a javascript function.

Code:
<li class="remove_chk2"><input name="delete[]"  type="checkbox" value="<?=$pics['PicID'];?>" /></li>
//$pics['PicID'] is from the db - the pic

<div class="page_button1">
<p>
<a href="javascript:confirmationMultiples('delete[]', <?=$this->galleryID;?>, <?php echo "'" .  $type . "'"; ?>)">Delete</a>
</p>  
</div>
So once clicked ('delete' button) one would get a pop up asking if all pictures should be deleted. But in actual fact the pictures are just flagged inactive in the db table for the pics.

Code:
function confirmationMultiples(ID, Request, Type) {
    	var answer = confirm("Are you sure you want to delete the selected pictures?")
	if (answer){
	
		alert("Entry Deleted")
		window.location = "http://mainevent.com/admin/galleries/delete-pics/pid/" + ID  + "/type/" + Type + "/id/" + Request;
	}
	else{
		alert("No action taken")
	}
}
// where request is the id for the gallery
// type is the type of gallery - event/venue gallery
// ID - should be the pics checked from the view on POST
WHat exactly am i doing wrong??? currently my URL reads as
Code:
http://mainevent.com/admin/galleries/delete-pics/pid/delete[]/type/event/id/313
I think the main hassle is from posting the form getting all the checkboxes in array delete[] to the js and then to the php controller that then initiates the delete by reading the parameter from the URL.

Pls help!!

10-15-2008, 02:28 AM
#2
swg is offline swg
Status: I'm new around here
Join date: Oct 2008
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

swg is on a distinguished road

  Old

Well in all honestly I am not too sure myself.

However a few things I noticed -

you're passing the 'delete[]' array as a string to the javascript function hence the URL which is currently being outputed.

What exactly do you want the URL to look like anyway? Because all you're currently doing is inserting an array into a URL without doing anything with it.

10-25-2008, 06:07 PM
#3
wesleyh is offline wesleyh
Status: I'm new around here
Join date: Oct 2008
Location:
Expertise:
Software:
 
Posts: 15
iTrader: 0 / 0%
 

wesleyh is on a distinguished road

  Old

You'll need to put a form around your entire <ul>.. Make sure it is set to post. Then you don't need to pass the variable to javascript. Make the delete button a submit button.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed