Avatar of debbieau1
debbieau1
Flag for United States of America asked on

jquery dialog and posting data

Would be great to help on this.  I'm sure someone with a good eye will see problem quickly.   It is not posting the value to the php script


		function myTester(thetitle)
		{
				$('<div>'+
				  '<input type="text" id="testrequest" placeholder="What is the name?" size="60"/>'+
				  '</div>').dialog({
				dialogClass:'shareClass',
			        title: thetitle,
			        width: 600,
					height: 300,
			        close: function(event, ui) { $(this).remove(); },
			        position: ['center','center'],
			        modal: false,
			        buttons: [
			            {
			                text: "Send Request",
			                click: function() { 
							$.ajax({
								url:'forms/sendResults.php',
								var testrequest=$("#testrequest").val(),
								type:'post',  
								data: $(testrequest).serialize(),
								success:function(result){
									$("button").html(result);
								}
							});
				  				$( this ).dialog( "close" ); 
							}
			            },
				     {
			                text: "Close",
			                click: function() { 
	
				  		$( this ).dialog( "close" ); 
					}
			            }

			        ]
			    });

Open in new window

AJAXjQuery

Avatar of undefined
Last Comment
debbieau1

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Tom Beck

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
debbieau1

ASKER
Thanks for such quick response.  Didnt solve it, but you did pick up one  syntax error.


This is what I have in the php script.

<?php echo "this is my test and should post value ".$_POST['testrequest'];

It should echo the value from the dialog.  The value is not posting to php script
debbieau1

ASKER
must not have cleared cache sorry it works.  thanks very much
leakim971

Try this :
function myTester(thetitle)
{
	$('<div><input type="text" id="testrequest" placeholder="What is the name?" size="60"/></div>').dialog({
		dialogClass:'shareClass',
		title: thetitle,
		width: 600,
		height: 300,
		close: function(event, ui) { $(this).remove(); },
		position: ['center','center'],
		modal: false,
		buttons: [
			{
				text: "Send Request",
				click: function() { 
					$.post('forms/sendResults.php', { testrequest: $(testrequest).val() }, function(result){ alert(result);$("button").html(result);});
					$( this ).dialog( "close" ); 
				}
			},
			{
				text: "Close",
				click: function() { 
					$( this ).dialog( "close" ); 
				}
			}
		]
	});
}

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
debbieau1

ASKER
sorry leakim, I accepted answer and didnt see your response.  You have always been terrific.
leakim971

no worry, please double check where you're putting :
 << testrequest : $("#testrequest").val(), >>
debbieau1

ASKER
Thanks so much
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.