• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

jquery create form and post dynamically

Im trying to write a simple script to create a form to submit values to a page via a POST method and then redirect to that form (as you cannot post on a redirect in jQuery apparently).

So, Ive got the following code:-
              
$('<form />', { action: 'sharer.php', method: 'POST' target:'_self' }).append(
                $('<input />', { type: 'text', id: 'rname', value: 'Name' }),
                $('<input />', { type: 'text', id: 'rdescription', value='Test description' }),
                $('<input />', { type: 'text', id: 'tags', value: 'text' }),
                $('<input />', { type: 'text', id: 'savebutton', value: 'Save' }).submit();
            );

Open in new window


But it doesnt seem to recognise the submit() command at the end.

Any ideas what Im doing wrong? Ive seen several examples of doing this, but like the way this is, as its very tidy.

Any suggestions?
0
tonelm54
Asked:
tonelm54
1 Solution
 
Rainer JeschorCommented:
Hi,
some typos and the wrong bracket order. Can you please try the following:
$('<form>', { action: 'sharer.php', method: 'POST', target:'_self' }).append(
	$('<input>', { type: 'text', id: 'rname', value: 'Name' }),
	$('<input>', { type: 'text', id: 'rdescription', value: 'Test description' }),
	$('<input>', { type: 'text', id: 'tags', value: 'text' }),
	$('<input>', { type: 'text', id: 'savebutton', value: 'Save' })).submit();

Open in new window


HTH
Rainer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now