simeonC Posted July 10, 2013 Share Posted July 10, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/280031-new-to-javascript-i-know-this-may-be-simple/ Share on other sites More sharing options...
Irate Posted July 10, 2013 Share Posted July 10, 2013 (edited) 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 July 10, 2013 by Irate Quote Link to comment https://forums.phpfreaks.com/topic/280031-new-to-javascript-i-know-this-may-be-simple/#findComment-1440237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.