Jump to content

Insert html form into javascript


jeff5656

Recommended Posts

Hi,

I know very little about javascript.  the following script echos out column width after a user drags the columns of a table.

I would like to capture the output into a form, so the user can submit it to their record and system will remember settings if they reload the screen:

$(function(){	

		var onSampleResized = function(e){
			var columns = $(e.currentTarget).find("th");
			var msg = "columns widths: ";
			columns.each(function(){ msg += $(this).width() + "px; "; })
			$("#sample2Txt").html(msg);
			
		};	 

Now this line: 

columns.each(function(){ msg += $(this).width() + "px; "; })

 

seems to echo out the widths of each column (the display says something like: "Column widths: 112px; 256px; 320px; 15px")

How can I have each value get echoed into a separate input box (type=text)?  Then when user submits the form, I will use php to process form and get the values into a database.

Link to comment
https://forums.phpfreaks.com/topic/279903-insert-html-form-into-javascript/
Share on other sites

You can use <input type="hidden" id="my_Id" value="" name="width_input"> in your HTML page and change $('#sample2Txt').html(msg) to $('#my_Id').attr('value',msg) or something like that and then you simply query the $_POST['width_input'] your PHP script (but do guard against cases where JavaScript has been disabled by the client by checking the value of $_POST['width_input'] in your PHP script (above suggestions are based on the assumption that you are using a POST request).

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.