6 Replies - 1285 Views - Last Post: 21 August 2012 - 07:09 AM

#1 SanmanX  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 32
  • Joined: 11-January 12

Jquery Dialog

Posted 06 August 2012 - 11:22 AM

Hey guys I'm using the jquery dialog plugin for pop up window when entering into a form. I was wondering how to correctly use a variable to be able to change the title option in the plugin. For example I have two pages one that adds a department and one that adds a user, so I want those to titles for each respective box.


$(document).ready(function(){
	$(".dialogBox").dialog({
		title:,
		width:500,
		height:400,
		modal:true,
		resizable:false,
	  draggable:false

	});
});

So I wonder how to do this correctly. I tried giving the div a title attributie then did:
title:$(this).attr('title')

but that gave me the title of the webpage.

Is This A Good Question/Topic? 0
  • +

Replies To: Jquery Dialog

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3493
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Jquery Dialog

Posted 06 August 2012 - 02:17 PM

View PostSanmanX, on 06 August 2012 - 08:22 PM, said:

So I wonder how to do this correctly. I tried giving the div a title attributie but that gave me the title of the webpage.

that’s because the scope for this is document. Javascript only knows function scope, hence the scope (even inside the object literal) is that of the nearest ancestor function, in this case the anonymous function tied to document.
Was This Post Helpful? 0
  • +
  • -

#3 rajesh.kakawat  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 43
  • Joined: 03-January 11

Re: Jquery Dialog

Posted 14 August 2012 - 02:45 AM

try this, just add title to div and don't write any javascript code related to title like below
$(document).ready(function(){
	$(".dialog").dialog({
		width:500,
		height:400,
		modal:true,
		resizable:false,
	  draggable:false

	});
});




html code
<div class="dialog" title="Rajesh dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<div class="dialog" title="MahesH dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


Was This Post Helpful? 0
  • +
  • -

#4 SanmanX  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 32
  • Joined: 11-January 12

Re: Jquery Dialog

Posted 20 August 2012 - 10:47 AM

I was able to figure it out by having a title on each of the corresponding pages and did:

title:document.getElementsByTagName('title')[1].innherHTML


Now i have a new problem. I am trying to find a away to change the text for the button depending which window im in. It crash because of my if statement, I'm wondering if someone could help me fix it.

var my_buttons = ["Add","Run Report", "Make Payment","Create","OK"];

$(document).ready(function(){
	$(".dialogBox").dialog({
		title:document.getElementsByTagName('title')[1].innerHTML,
		width:500,
		height:400,
		modal:true,
		resizable:false,
	  draggable:false,
		buttons: [
		if($('.dialogBox').hasClass('.add'))
	{
		text:my_buttons[1],
    click:function(){document.getElementsByTagName("form")[0].submit();}
	},

		else{

	{
		text:my_buttons[4],
    click:function(){document.getElementsByTagName("form")[0].submit();}
	},

		 }

		{
			text:"Back",
		  click:function(){$(this).dialog("close");
			window.location.href = backURL;
			}
		}
	]
	});
});


Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3493
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Jquery Dialog

Posted 20 August 2012 - 12:32 PM

you have 2 <title> elements in your HTML?
Was This Post Helpful? 0
  • +
  • -

#6 SanmanX  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 32
  • Joined: 11-January 12

Re: Jquery Dialog

Posted 21 August 2012 - 07:02 AM

View PostDormilich, on 20 August 2012 - 12:32 PM, said:

you have 2 <title> elements in your HTML?


I guess, for some reason if I put in a 0 instead of the 1 it gives me the title of the home page. The 1 gives me the current page I'm on.
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3493
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Jquery Dialog

Posted 21 August 2012 - 07:09 AM

View PostSanmanX, on 21 August 2012 - 04:02 PM, said:

I guess, for some reason if I put in a 0 instead of the 1 it gives me the title of the home page.

well, that is what the <title> element is supposed to do ...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1