jQuery - wstawienie tekstu do inputa

0

Witam serdecznie,
Mam taki skrypcik:

<!DOCTYPE html>  
<html lang="pl"> 
<head> 
	<meta charset="utf-8">
	<link rel="stylesheet" href="css/jquery-ui-1.8.9.custom.css"> 
	<script src="js/jquery-1.4.4.min.js"></script> 
	<script src="ui/minified/jquery.ui.core.min.js"></script> 
	<script src="ui/minified/jquery.ui.widget.min.js"></script> 
	<script src="ui/minified/jquery.ui.mouse.min.js"></script> 
	<script src="ui/minified/jquery.ui.button.min.js"></script> 
	<script src="ui/minified/jquery.ui.draggable.min.js"></script> 
	<script src="ui/minified/jquery.ui.position.min.js"></script> 
	<script src="ui/minified/jquery.ui.resizable.min.js"></script> 
	<script src="ui/minified/jquery.ui.dialog.min.js"></script> 
	<script src="ui/minified/jquery.effects.core.min.js"></script> 
	<script src="ui/minified/jquery.effects.blind.min.js"></script> 
	<script src="ui/minified/jquery.effects.explode.min.js"></script>
<style> 
		body { font-size: 62.5%; }
		label, input { display:block; }
		input.text { margin-bottom:12px; width:95%; padding: .4em; }
		fieldset { padding:0; border:0; margin-top:25px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
		.ui-dialog .ui-state-error { padding: .3em; }
		.validateTips { border: 1px solid transparent; padding: 0.3em; }
	</style>  
	<script>  
  
	
	


	$("#close-button").click(function() {
  $(this).oneTime(1000, function() {
    $(this).parent(".main-window").hide();
  });
});
$("#cancel-button").click(function() {
  $("#close-button").stopTime();
});
	// increase the default animation speed to exaggerate the effect
	$.fx.speeds._default = 500;
	$(function() {
		$( "#dialog" ).dialog({
			autoOpen: false,
			height: 240,
			width: 240,
			show: "explode",
			modal: true,
			hide: "explode",
			position: ['center','center'],
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
					$(this).dialog('destroy');
				}
			}
		});
 
		$( "#opener" ).click(function() {
			$("#dialog").dialog( "open" );
			
			return false;
		});
	
	
		$( "#kasownik" ).click(function() {
			$("#dialog-confirm").dialog( "open" );
			return false;
		});
	});
	</script> 
	
	
<script> 	

	function deleteconfirmed(id){
	$.post('dane.php',{pokaz:'users'},function(odebrane_dane){
	$('#users').html(odebrane_dane)
	})
	setTimeout("odswiez_diva()", 1000);
	}

function odswiez_diva(){
	$.post('dane.php',{pokaz:'users'},function(odebrane_dane){
	$('#users').html(odebrane_dane)
	})
	setTimeout("odswiez_diva()", 1000);
	}

$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#name" ),
			email = $( "#email" ),
			password = $( "#password" ),
			allFields = $( [] ).add( name ).add( email ).add( password ),
			tips = $( ".validateTips" );
 
		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}
 
		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}
 
		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			buttons: {
				"Create an account": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
 
					bValid = bValid && checkLength( name, "username", 3, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
					bValid = bValid && checkLength( password, "password", 5, 16 );
 
					bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. [email protected]" );
					bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
 name
					if ( bValid ) {
			   $.post('test.php', { 'name' : $('#name').val(),'email' : $('#email').val(),'send': 'ok'}); 
				
						$( this ).dialog( "close" ); 
						var editor = $('#dialog-form textarea').ckeditorGet();
                  editor.destroy();
						$(this).dialog('destroy');
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			open: function(){
			var ckoptions = { 	langCode: 'pl', skin : 'kama',
						width:600,
						toolbar:
						[
							['Source', '-', 'Bold', 'Italic', 'Underline', 'Strike', 'LeftJustify' ],
							['Image', 'Link', 'Unlink', 'Anchor'],
							['Cut','Copy','Paste','PasteText','PasteFromWord','-','Find','Replace'],
							['Undo','Redo','-','SelectAll','RemoveFormat'],
							['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
							['NumberedList','BulletedList'],
							['Format'],
							['TextColor','BGColor'],
							['Font','FontSize'],
						]  
	}
			//$(this).append('<textarea class="editor"></textarea>');
			$(this).find('textarea.editor').ckeditor(ckoptions); //ckoptions
		},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
				$("#users").toggle('slow'); 
							//$('#users').load('slow').load();
							//$("#users").load("dane.php");
							//$("#users").toggle('slow'); 
							odswiez_diva();$("#users").toggle('slow');
							$(this).dialog('destroy');
			}
		});
 
		$( "#create-user" )
			.button()
			.click(function() { 
			
				//$('#dialog-form').load('index.php?id='+id);
				$( "#dialog-form" ).append( "<p>" +
							"<b>" + name.val() + "</b>" + 
							"<b>" + email.val() + "</b>" + 
							"<b>" + password.val() + "</b>" +
						"</p>" ); 	$( "#dialog-form" ).dialog( "open" );
				//$('#dialog-form textarea').ckeditor();
			});
			
	 $( "#dialog" ).dialog({	
			autoOpen: false,
			height: 240,
			width: 240,
			show: "explode",
			modal: true,
			hide: "explode"
		});	
		
		$( "#dialog-confirm" ).dialog({
			autoOpen: false,
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"Delete all items": function() {
				$("#users").toggle('slow'); 
				deleteconfirmed();$("#users").toggle('slow'); 
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});	
			
	});
	</script> 
</head> 
<body> 

<div class="demo"> 
<button id="create-user">Create new user</button> 



<div id="dialog-form" title="Create new user"> 
	<p class="validateTips">All form fields are required.</p> 
 
	<form method = "post"> 
	<fieldset> 
	<input type="text" name="id-produktu" value="">
		<label for="name">Name</label> 
		<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> 
		<label for="email">Email</label> 
		<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" /> 
		<label for="password">Password</label> 
		<textarea name="password" id="password" value="" class="editor"></textarea>
	</fieldset> 
	</form> 
</div> 
</div>

Po kliknięciu na button wyskakuje mi okienko - i tak ma być. Chciałbym jakoś za pomocą tego buttona uzupełnić
inputa: <input type="text" name="id-produktu" value=""> jakąs dowolną wartością ( np. "mój kod").

Czyli: klikamy buttona i wyskakuje nam okienko z uzupełnionym inputem. Teraz wszystko jest ok, ale input
jest pusty....

Wie ktoś może jak to zrobić??

Z góry dziękuje za pomoc,
Northwest

0
  1. Stosuj znacznik <code class="html"> do kolorowania składni jezyka HTML
  2. Stosuj znacznik <code class="javascript"> do kolorowania skladni jezyka JS
  3. Nikomu raczej nie bedzie sie chcialo analizowac takiego dlugiego listingu lecz jezeli pytasz jak ustawisz wartosc dla atrybutu value to podpowiadam - funkcja val():
$('#foo').val('foo bar');

1 użytkowników online, w tym zalogowanych: 0, gości: 1