Jump to content

jQuery dialog


x1nick

Recommended Posts

Just trying to get to grips with jQuery, and while I have ajax etc working fine. I can't get dialog boxes to work how I want.

 

Basically I have a list, each item has a update option. When clicked I would like a dialog box to open to request confirmation.

 

I have created a div for the message box

<div id="dialog" title="Update Template"></div>

 

With this I need to fill the content of the div with a message such as 'Are you sure you want to update "##templatename##"?'

 

The code that currently is the button is

<a href="#" title="Update Template" id="update">Update</a>

 

And the jquery config

<script type="text/javascript">
$(function(){
	// Dialog			
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		modal: true,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	$('#update').click(function(){				
		$('#dialog').dialog('open');
		return false;
	})
});
</script>

 

Im still learning javascript so not too sure if I could use an associative array somehow.

So each item would be [templateid][templatename]

Then the message box be given the template id and extract the template name from the array

 

Any help on this would be really appreciated.

Link to comment
https://forums.phpfreaks.com/topic/171412-jquery-dialog/
Share on other sites

After playing some more I tried this

onclick="$.tplid = '<?=$result['tplid']?>';$.message = 'Are you sure you want to update the template \'<?=$result['tplname']?>\'?';"

Added that into the link on the list

 

And updated the jquery config to

	$('#update').click(function(){	
	    $('#dialog').html($.message);
		$('#dialog').dialog('open');
		return false;
	})

Which seems to work.

 

Now I don't know how to make this work for multiple lines of data. As I have anything from 1-100 rows of data being shown each one will need a unique id, how would I edit the code above to cope with this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/171412-jquery-dialog/#findComment-903985
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.