Jump to content

Recommended Posts

I would like to prompt a form when a certain element is clicked I have the

onClick attribute and know how to call a function.

 

I need to know how to display a form through javascript that will then be inserted into an sql database...

So if i can be placed at a starting line that would be great

Just do

<a href="#" id="new_form">Click here to launch new form.</a><br><br><span id="formOP"></span>
and in your JavaScript part, do this (easy solution with jQuery is in a spoiler below).

 

function returnForm(){
var form = '<form method="POST" action="" name="newform"><fieldset><dl><dt>Username</dt><dd>Enter your username: <input type="text" name="username" placeholder="Username"></dd></dl></fieldset></form>'; return form;
}
function doForm(){
document.getElementById("formOP").innerHTML = returnForm();
return false;
}
window.onload = function(){
var c = document.getElementById("new_form");
c && c.onclick ? c.onclick = doForm() : return false;
};

// We assume jQuery and our returnForm() functions are still defined
jQuery(document).ready(function(){
jQuery('#new_form').click(function(e){
e.preventDefault();
e.stopPropagation();
jQuery('#formOP').html(returnForm());
});
});

 

 

Edit: Fixed a small quotation error. Also, this is just a dummy function, you have to style and customize this code, of course.

Edited by Irate
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.