View Full Version : Disabling enter from submitting a form.
bacterozoid
07-15-2002, 11:12 PM
Ok, if you'll go here: http://www21.brinkster.com/jonshtmlhelp/contact.htm you can see the search form on the left side of the page. The code that goes in the head tag for that is here:
http://www30.brinkster.com/jonshtmlhelp/js/searchhead.js
(Right-click and save as to view)
The HTML for the form is this:
<form method=get action="javascript:void(0)" onsubmit="search(this);">
<p align="center"> <br>
<input type=text name=srchval size="10" style="FILTER: alpha(opacity=50);" style="color: #000000; background-color: #B4B4B4; font-family: arial; font-size: 8pt; border: 1 solid #808080" onChange="javascript:this.value=this.value.toLowerCase();"><br>
<input type=submit value="Search2" style="color: #000000; font-family: arial; font-size: 8pt; background-color: #C0C0C0; border: 1 solid #808080"></p>
</form>
I have to have it go to lowercase because my search script is case-sensitive, and it just works better in lower case. (If that is relevant)
Pressing enter does not process the script to make the text lowercase, so I want to make it so only clicking on search will submit the form.
I went here: http://developer.irt.org/script/2066.htm and tried a few things with the script, but I don't know what to do.
ACJavascript
07-16-2002, 12:34 AM
try this, it might just work hehehe. (never does though j/k)
<form method="GET" action="javascript:void(0);" onSubmit="return false">
<p align="center"> <br>
<input type=text name=srchval size="10" style="FILTER: alpha(opacity=50);" style="color: #000000; background-color: #B4B4B4; font-family: arial; font-size: 8pt; border: 1 solid #808080" onChange="java script:this.value=this.value.toLowerCase();"><br>
<input type=submit value="Search2" style="color: #000000; font-family: arial; font-size: 8pt; background-color: #C0C0C0; border: 1 solid #808080"></p>
<input type="submit" value=" - Go - " onclick="search(this)">
</form>
Hope this helps :D:D
bacterozoid
07-16-2002, 12:51 AM
well, i, uh, got it working...kinda...problem is, it reads the first part of my javascript, then just stops and doesnt display the results...any ideas?
No, that...doesn't work. I get what you are trying to do, but I got an error, then fixed it so I didn't get that error, but then when I pressed go my search script didnt work right...and neither did my lowercase thingie...
although the disable enter script functions
is it maybe possible to make both onClick and onSubmit to have the lowercase script attached to them?
bacterozoid
07-16-2002, 02:05 AM
Alright, here it is:
This is the JS that processes the search and pops up the page with the results and such:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var item = new Array();
// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
c=0; item[c]=new Array("default.htm","","Home Page","index,main,start,home,news,recent","The site home page. Find recent news and updates here.");
c++; item[c]=new Array("contact.htm","","Contact Me","contact,email,comments,comment","Contact me with whatever it is you need to contact me about.");
page="<html><head><title>Search Results</title><style type=\"text/css\">body{scrollbar-face-color:#C1C1C1\;scrollbar-shadow-color:#C3C3C3\;scrollbar-highlight-color:#C4C4C4\;scrollbar-3dlight-color:#FFFFFF\;scrollbar-darkshadow-color:#000000\;scrollbar-track-color:#C0C0C0\;scrollbar-arrow-color:#A2A2A2\;}</style><style type=\"text/css\">A:link { text-decoration: none\; color:\"#006C6C\" }A:visited { text-decoration: none\; color:\"#006C6C\" }A:hover { text-decoration: none\; color:\"303030\" }</style><base target=\"_blank\"></head><body bgcolor=\"#C1C1C1\"><p align=\"center\"><font face=\"Arial\" size=\"3\"><b>Search Results<br></b></font><font face=\"Arial\" size=\"1\">(All links will open in a separate window)</font><font face=\"Arial\" size=\"3\"></p></body></html>";
function search(frm) {
win = window.open("","","scrollbars");
win.document.write(page);
txt = frm.srchval.value.split(" ");
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd[i] = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd[i] += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w] = 0;
}
win.document.write("</table><br><br>Total found: "+total+"<br><br><br><p align=\"center\"><a href=\"javascript:window.close()\" target=_top><font size=\"1\" face=\"Arial\">Close Window</font></a></body></html>");
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"/10<br>";
line += item[which][4] + "<br><!--"+link+"--><br><hr width=\"70%\" size=\"1\" color=\"#535353\"><br></td></tr>";
wind.document.write(line);
return 1;
}
// End -->
</script>
Here is the HTML of the form that you type your search info in:
<form method=get action="javascript:void(0)" onSubmit="return false">
<table>
<tr><td>
<p align="center"><input type=text name=srchval size="10" style="color: #000000; background-color: #B4B4B4; font-family: arial; font-size: 8pt; border: 1 solid #808080" onChange="javascript:this.value=this.value.toLowerCase();"><br>
<input type=submit value="Search" style="color: #000000; font-family: arial; font-size: 8pt; background-color: #C0C0C0; border: 1 solid #808080" onclick="search(this);"></p>
</td></tr>
</form>
My problem is that the search doesn't process all the way...you can test it here:
http://www21.brinkster.com/jonshtmlhelp/search.htm
glenngv
07-16-2002, 03:31 AM
why not use input type=button?
<input type="button" value="Search" onclick="search(this);">
bacterozoid
07-16-2002, 03:33 AM
I don't know...its not really relevant though, because nothing changes when i do that.
glenngv
07-16-2002, 04:59 AM
you pass the wrong parameter in the search() function. The parameter should be the form object not the element button as you did search(this). Also, you should name your form.
So your real problem is not on submitting the form, but on the calling of the function.
input type=submit works though it's better to just use input type="button"
<form name="myform">
<table>
<tr><td>
<p align="center"><input type=text name=srchval size="10" style="color: #000000; background-color: #B4B4B4; font-family: arial; font-size: 8pt; border: 1 solid #808080" onChange="java script:this.value=this.value.toLowerCase();"><br>
<input type="button" value="Search" style="color: #000000; font-family: arial; font-size: 8pt; background-color: #C0C0C0; border: 1 solid #808080" onclick="search(document.myform);"></p>
</td></tr>
</form>
Originally posted by bacterozoid
I don't know...its not really relevant though, because nothing changes when i do that.
bacterozoid
07-16-2002, 03:26 PM
Ah, nevermind that. I just took the code that I posted earlier and pasted it into frontpage, then changed the search() function thing have the title of the form in it instead of 'this' it works just how i want it to. thanks! - yippie, figured something out myself for a change, hehe
Well, um, whatever you did seems to work ok. When I press enter the form just clears its self, and the lowercase thing and everything seems to work fine. Unless there is a way to fix the fact that the form clears when you submit, i guess i don't need anymore help...for now, hehe. thanks a bunch!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.