whi
whi

Reputation: 2750

html link onclick pop up a form

i'd like to pop up a form when click a link.

<a title='%s' onclick='return popupform()'  href='#'> ABC </a>

the form is like:

<form id="contactus" action="javascript:submit_form()" method="post" accept-charset="UTF-8">
<input type="hidden" name="submitted" id="submitted" value="1">
    <label for="chinese">Chinese: </label><br>
    <input type="text" name="cs" id="cs" value="" maxlength="50"><br>
<label for="english">English:</label><br>
    <input type="text" name="en" id="en" value="" maxlength="50"><br>
    <input type="submit" name="Save" value="Save">
    <input type="submit" name="Delete" value="Delete">
    <input type="submit" name="Add" value="Add">
    <input type="submit" name="Close" value="Close">
</form>

how to achieve it?

Upvotes: 1

Views: 16867

Answers (2)

Hazem Salama
Hazem Salama

Reputation: 15101

Pop-ups are simple div elements on the page that would be initially hidden and then revealed when some event takes place, like a mouse click. You then need to adjust the look of that div so it appears as a pop-up to the user, i.e. center the div on the page, raise its z-index so it layers above all, adjust the opacity to give the dimming effect, and so on. Obviously it is a lot of work if you decide to roll your own. Otherwise, if you are OK with using jquery, you can take advantage of the jqueryui dialog element

Upvotes: 1

tptcat
tptcat

Reputation: 3961

Wrap your form in a div:

<a title="%s" class="show_form" href="#"> ABC </a>

<div id="form_wrapper">
    <form id="contactus" action="javascript:submit_form()" method="post" accept-charset="UTF-8">
    ... truncated for brevity
    </form>
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

And some CSS:

​#form_wrapper {
    display:none;
}​

And then some JavaScript using jQuery:

$('a.show_form').on('click', function() {
    $('#form_wrapper').show();
});​​​​​

And if you really mean a popup window, or commonly called a "modal" window, look here: http://jqueryui.com/demos/dialog/#modal-form

Upvotes: 3

Related Questions