How to disable Submit button is get method? - javascript

I want to search dog so When i click on submit button the URL looks like http://localhost/myproject/search.php?q=dog&submit= i want to disable the submit button is the URL navigation it will look http://localhost/myproject/search.php?q=dog.
My code -
<form id="formSearch" name="formSearch" method="get" action="search.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="67%" align="right" valign="top">
<input type="text" name="search" id="search" class="search_text_box" placeholder="Search" autocomplete="off"/>
</td>
<td width="33%" align="left" valign="top">
<input type="submit" name="submit" id="button" value=" " style="cursor:pointer;" class="search_btn" />
</td>
</tr>
</table>
</form>
Please help me how to disable the submit button in URL Navigation?
If any jquery or javascript code please post your answer below
Search Image Screenshot

Don't give the submit button a name attribute.

Remove name attribute in to your submit button
<form id="formSearch" name="formSearch" method="get" action="search/">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="67%" align="right" valign="top">
<input type="text" name="search" id="search" class="search_text_box" placeholder="Search" autocomplete="off"/>
</td>
<td width="33%" align="left" valign="top">
<input type="submit" id="button" value=" " style="cursor:pointer;" class="search_btn" />
</td>
</tr>
</table>
</form>

in add to quentin:
when u use GET method the query string goes to the server via URL in the 'name=value' form.so if u dont want to show the submit in the URL than remove the 'name' attribute from the submit.
and instead u can use $_POST method if u dont want to send your query string via URL.

if you want to customize the code with input type submit name you can use javascript or jquery
Code :
window.location='/search.php?q='+qvariable;
otherwise remove the name attribute in input type=submit
<input type="submit" id="button" value=" " style="cursor:pointer;" class="search_btn" />

Try this:
Here you can set method="post" in the form tag OR
Remove name from property from submit button.

Related

HTML Form, onclick="this.disabled=true;this.value='Sending, please wait...'; return false;" disables the button but never submits the form

I am making a simple image board and the onclick function is being very finicky.
<div id="makeApost">
<form name="post" method="post" action="post.php?new" enctype="multipart/form-data" >
<table class="postForm" id="postForm">
<caption><h1>Create Thread</h1></caption>
<tr data-type="Comment">
<td style="background-color:#ff33ff;">Comment</td>
<td>
<textarea id="com" name="com" cols="48" rows="4" wrap="soft"></textarea>
</td>
</tr>
<tr data-type="File" >
<td style="background-color:#ff33ff;">File</td>
<td><input id="file" name="file" type="file"></td>
<td><input id="submit" type="submit" onclick="this.disabled=true;this.value='Sending, please wait...'; this.form.submit();"></td>
</tr>
</table>
</form>
</div>
This is the post form, i have also tried:
<td><input id="submit" type="submit" onclick="this.form.submit();this.disabled=true;this.value='Sending, please wait...';"></td>
But this does not disable the button when it has been pressed and allows for multiple submits which could lead to spamming.
Disable the button on submit of the form, not the click of the button.
<form onsubmit="document.getElementById('btnSubmit').disabled=true;">
<input type="submit" id="btnSubmit" />
</form>

How to get value of a HTML tag receiving from ajax call

I am receiving below html from vbscript page by ajax call.
<html>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="100%" valign="top">
<div id="xyz"></div>
<input name="a1" type="hidden" value="">
<input name="a2" type="hidden" value="586546d5">
<input name="a3" type="hidden" value="13025">
<br clear="all">
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Is it possible to get value of input tag where name="a2" in ajax. i.e we want value 586546d5 in the variable.
You can convert html string into jquery object and then get element in it:
$(returnehtml).find('[name=a2]').val();
use query selector
document.querySelector('input[name=a2]').value

The Submit Button doesn't work in Chrome or Firefox, but Works in Internet Explorer

I had a situation where the Submit Button would not work if you clicked on it in Firefox and Chrome, but it worked as it should in Internet Explorer.
Even odder, I found that I could "tab" to the button and hit enter and it would work. This was a portion of the form code:
<form id="product_form" name="product_form" method="post" onsubmit="return validateProductForm();" action="product-photo-mail.php" enctype="multipart/form-data">
<table width="100%" border="0">
<tr>
<td class = "left_side" width="30%">Quantity:</td>
<td class = "right_side" width="60%">
<select name = "quantity_cards">
<option>50</option>
<option>75</option>
<option>100</option>
<option>125</option>
<option>150</option>
<option>more</option>
</select>
</td>
</tr>
.
.
.
<tr>
<td colspan="2" align="center">You're almost done!</td>
</tr>
<tr>
<td colspan="2" align="center"><br />After you submit your order we will send over your digital proof for approval!</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="button1" id="button1" class="formbutton" value="Submit My Order" />
</td>
</tr>
</table>
</form>`
When I moved the button above the text, it worked on all browsers as I would expect. I have no idea why this would happen. I spent hours trying to get this to work and the only thing I could get to work is swapping the order:
.
.
<tr>
<td colspan="2" align="center">
<input type="submit" name="button1" id="button1" class="formbutton" value="Submit My Order" />
</td>
</tr>
<tr>
<td colspan="2" align="center">You're almost done!</td>
</tr>
<tr>
<td colspan="2" align="center"><br />After you submit your order we will send over your digital proof for approval!</td>
</tr>
</table>
</form>
I would like to have the text first and the submit button, but I am at my wits end here. Has anyone experienced this before?
Is it not possible to provide a link?
Is there not perhaps an hidden element that is covering your submit button? That would explain why you can tab to the button, but not click it.
Try to use <button> tag instead of <input>.

How to post the information of web form's submit button to the server in cocoa?

Basically, I know how to post web form data using NSURLConnection. But the problem is there are 3 submit buttons in the web form, and when you click any one of them, the server will check the one which has been clicked. In iOS or cocoa, how am I gonna tell the server about this?
Here is the code of the form in the html:
<form name="myform" action="checkLogin.jsp" method="post" onSubmit="return checkSubmit();">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td height="38" width="80" class="login_txt">account: </td>
<td width="200"><input type="text" class="editbox4" name="username" id="username" value="" size="20" maxlength="24"></td>
<td width="240"> </td>
</tr>
<tr>
<td height="35" class="login_txt">password: </td>
<td><input type="password" class="editbox4" name="password" id="password" size="20" maxlength="24" style="height: 25px;vertical-align: middle;"> <img src="public/images/luck.gif" width="19" height="18" style="vertical-align: bottom;"></td>
<td> </td>
</tr>
<tr>
<td height="35" class="login_txt">ip: </td>
<td><span class="login_txt">118.228.173.165</span><input type="hidden" name="ip" value="118.228.173.165"> </td>
<td> </td>
</tr>
<tr>
<td height="35" colspan="3"><input type="submit" value="connect" class="login_button" name="action"> <input type="submit" value="disconnect" class="login_button" name="action"> <input type="submit" value="manage" class="login_button" name="action"></td>
</tr>
</table>
</form>
Submit inputs are a little bit special in a form.
As you may know, a browser always sends values for every input/textbox/anything in the form. Except for the submit buttons. It will only send the submit button that has been clicked.
For example, if you click on the connect button, the data sent will look like this:
username: hello
password: world
action: connect
Or, should you click on the disconnect button:
username: hello
password: world
action: disconnect
Thus, you can send the right action in your NSURLConnection to select the action that must be done by the server.

Auto Submitting the Form

I am facing one problem in the following code , Form is going to submit when i press enter in Keyword text field. there no such enter event bind in java script. Still this problem is happing
But when I remove the <form> tag it works fine ,
Please help .. if there is any mistake
<form action="" method="post" id="businessSearchForm" name="businessSearchForm">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" HEIGHT="100%" WIDTH="100%" CLASS="searchproperty">
<TR>
<TD ALIGN="left" COLSPAN="4" class="boldText"> Business Search</TD>
</TR>
<TR>
<TD ALIGN="left" WIDTH="20%" class="boldText"> Search For</TD>
<TD WIDTH="25%"><INPUT TYPE="radio" NAME="searchfor" VALUE="1" checked="checked">Product <INPUT TYPE="radio" NAME="searchfor" VALUE="2">Company</TD>
<TD ALIGN="left" WIDTH="20%" class="boldText"> Business Type</TD>
<TD WIDTH="30%"> <SELECT NAME="businessType" ID="businessType" CLASS="dropDown"></SELECT></TD>
</TR>
<TR>
<TD ALIGN="left" class="boldText"> Country</TD>
<TD> <SELECT ID="country" NAME="country" CLASS="dropDown"></SELECT></TD>
<TD ALIGN="left" class="boldText"> State</TD>
<TD> <SELECT ID="state" NAME="state" CLASS="dropDown"></SELECT></TD>
</TR>
<TR>
<TD ALIGN="left" class="boldText"> Keywords <span class="mendotory">*</span></TD>
<TD COLSPAN="3"> <INPUT TYPE="text" maxlength="40" SIZE="40" tabindex="1" name="keywords" id="keywords" value=""> <INPUT TYPE="button" CLASS="btn" VALUE="Search" ONCLICK="javascript:processBusinessSearch();"/> </TD>
</TR>
</TABLE>
</form>
Another case of the "single textbox submit" problem in IE, see this SO question: "IE needs 2 textboxes to submit a button?".
One workaround is to place another textbox in the form with a style of "display: none"; that way, the enter button won't trigger the submit event. Or, you can use some Javascript to trigger the submit event... it all depends on what you want to achieve.
I'm not sure I've interpreted your question, but I believe what you're wanting is for your processBusinessSearch() function to be called when the form is submitted, regardless of whether the user pressed the submit button or pressed enter.
For this, take a look at the submit event - add a handler for this event which calls your function.
Something like this should do it:
$("#keywords").keypress(function(e) {
// if 'enter' is pressed
if(e.which == 13) {
return false;
}
});
Try using the onsubmit event on the form instead:
<form onSubmit="return processBusinessSearch()" ...
$("#keywords").keypress(function(e){
if (e.which == 13)
$("#businessSearchForm").submit();
});

Categories

Resources