Jump to content


Photo

New to javascript I know this may be simple..


  • Please log in to reply
1 reply to this topic

#1 simeonC

simeonC

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 10 July 2013 - 09:12 AM

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



#2 Irate

Irate

    Advanced Member

  • Members
  • PipPipPip
  • 358 posts
  • LocationHamburg, Germany
  • Age:17

Posted 10 July 2013 - 04:54 PM

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:&nbsp;<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;
};
Spoiler


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, 10 July 2013 - 04:59 PM.

Quod placet mihi non placeat tibi. - What I think to be good must not always equal your perception of it.

I am not perfect. I try a lot with the code I provide and I don't guarantee for it to work as I have mostly no option to test it on my mobile phone. I do apologize for any inconvenience I caused, but if I do happen to have helped, liking my posts or marking them as to have solved or answered your question would be nice.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com