Todo :
Close a form by clicking a button. Any solution because I tried more and I saw more method but no result. None of these methods work. any idea.
<form method="post">
<input type="button" value="Close Window"
onclick="window.close()">
</form>
<input type="button" name="cancelvalue" value="CANCEL"
onClick="self.close()">
If you want the window to get closed by javascript, then javascript must have opened that window in the first place to close it.
But, there is some hack using "self redirection", And the following will work easily open(location, '_self').close();
<form method="post">
<input type="button" value="Close Window"
onclick="open(location, '_self').close();">
</form>
<input type="button" name="cancelvalue" value="CANCEL"
onClick="open(location, '_self').close();">
Related
I'm trying to make a HTML form that on submit does a google search with JS.
This is the HTML:
<form name="form">
<input type="text" name="search" id="searchBox" onkeyup="changeLogo()" autofocus>
<input type="submit" id="button" value="Submit" onclick="googleSearch()">
</form>
And the JS function:
function googleSearch() {
var searchText = document.getElementById("searchBox").value;
window.location.href = "http://google.com/";
}
The Google URL isn't right but it isn't redirecting at all.. I put alert(searchText) in the function and the alert showed so not really sure what's going on.
If you use button type as 'submit', it will submit your form.
So you can change your button from
<input type="submit" id="button" value="Submit" onclick="googleSearch()">`
to
<input type="button" id="button" value="Submit" onclick="googleSearch()">
It will work.
because the page refreshed when you click submit button before excuting localtion.href line
try change with your code like below
<form name="form" onsubmit="return false">
....
</form>
Your form is submitted which might be the issue. Change the type="submit" to type="button" this will make sure the form is not submitted on click of this button
I want to abstract the file-browse dialog from the user and only show one button for upload, like so:
<input type="button" id="uploadFile" value="Upload" />
<div class="hidden">
<form id="uploadFileForm" method="post" enctype="multipart/form-data">
<input type="file" id="browseForFiles" />
<input type="button" id="submitFile" value="Submit File" runat="server"
onclick="return true;"
onserverclick="SubmitFile_Click" />
</form>
</div>
$("#uploadFile").click(function () {
// trigger hidden file dialog
$("#browseForFiles").click(); // works
});
$("#browseForFiles").change(function () {
$("#submitFile").click(); // doesn't work; doesn't call onserverclick
});
Physically clicking on the submitFile button works fine and calls the server-side method, but since I want the actual server-side button to be hidden, the user can't physically click it. How do you fake a physical click in jQuery/Javascript?
EDIT :
I also tried:
<input type="submit" id="submitFile" value="Submit File" runat="server"
onclick="return true;"
onserverclick="SubmitFile_Click" />
$("#uploadFileForm").submit(); // doesn't work either
Have you tried this?
$('#uploadFileForm').submit()
$("input[id$='submitFile']").click(); works.
I didn't realize that ASP.NET was replacing the ID of the element to something like ctl00_PlaceHolderMain_submitFile even if regular HTML controls were used!
$("input[id$='submitFile']")[0].click(); works as well.
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?
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
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
I have the following snipet in a page. I cannot for the life of me figure out why the form is not submitting when clicking the button1 element. I get an error in IE syaing that this object does not support this property or method. I put the document.poform in an alert, and it alerts a form object. I get the feeling that I am missing something super obvious maybe??
<pre>
<?
var_dump($_POST);
?>
</pre>
<form action="" method="post" name="poform">
<input name="test" type="text" />
<input name="button" type="button" value="button1" onclick="document.poform.submit();" />
<input name="submit" type="submit" value="button2" />
</form>
Since you have an <input> named submit, document.poform.submit is that <input>, not the submit() method.
Use a different name.
Change type="button" to type="submit"
I am trying to submit the data for this form, which has 3 different buttons:
<form action="/game.php?village=8404&screen=market&mode=own_offer&action=modify_offers&h=85fd1491" method="post">
<input class="btn btn-cancel" type="submit" value="Delete" name="delete">
<input type="text" size="2" name="mod_count" value="1" onkeydown="return no_enter(event)">
<input class="btn" type="submit" value="Increase" name="increase">
<input class="btn" type="submit" value="Reduce" name="decrease">
</form>
I would like to either submit the data in the same manner of "increase" or click that submit button. Ideally, I wouldn't have to replicate the URL which appears after the form action= as this varies from page to page.
When the form has a definite id, I've been using:
$('#thisFormId input[type=submit]').click();
But can't work out.
So how I can do that in this instance?
If I understand the questions:
$("input[name=increase]").click();
will trigger the click event of the Increase button and submit the form, which is what you want?