...

View Full Version : Changing the "onsubmit" in a form?



price
01-24-2005, 04:10 PM
I have a bit of a complicated form on my website. It searches by a keyword and value. It works great for the way I have had search objects defined in the past (but I have changed all the keywords tied to me search objects)

Here is what I currently have:

<form NAME="find_spec" METHOD="POST" ACTION="<*SearchResultspageURL*>" onSubmit="this.find_spec.value=this.Keywrd.value + ' Home1';">
<font face="Arial, Helvetica, sans-serif">Search within home1<br>
</font> <input TYPE="TEXT" NAME="Keywrd" size=30 maxLength=50 align=bottom width="154">
<input TYPE="HIDDEN" NAME="find_spec" Value="">
<input type="hidden" id="searchtype" name="searchtype" value="AND">
<input type="image" NAME="btnSearch" ID="Search" src="<*ImageURL*>btn_search_tw.gif" border="0">
</form>
<form NAME="find_spec" METHOD="POST" ACTION="<*SearchResultspageURL*>" onSubmit="this.find_spec.value=this.Keywrd.value + ' Home2';">
<font face="Arial, Helvetica, sans-serif">Search within home2<br>
</font> <input TYPE="TEXT" NAME="Keywrd" size=30 maxLength=50 align=bottom width="154">
<input TYPE="HIDDEN" NAME="find_spec" Value="">
<input type="hidden" id="searchtype" name="searchtype" value="AND">
<input type="image" NAME="btnSearch" ID="Search" src="<*ImageURL*>btn_search_tw.gif" border="0">
</form>

As you can see this will show 2 different, nearly identical boxes, buttons, etc.

What I need is a form where there is only 1 text box, but the "onSubmit="this.find_spec.value=this.Keywrd.value + ' Home1';">" field can be changed via a drop down box (or something similar) So that instead of having duplicates the form will be much cleaner.

Is this possible?

ronaldb66
01-24-2005, 04:18 PM
What do you process these forms with? I'm not too familiar with forms, but I can't see major problems in sending along another value to control which kind of processing is done.
To come up with anything specific, though, you'll need to supply a bit more detailed information.

price
01-24-2005, 04:25 PM
What do you process these forms with? I'm not too familiar with forms, but I can't see major problems in sending along another value to control which kind of processing is done.
To come up with anything specific, though, you'll need to supply a bit more detailed information.

It is a part search on my website. Each of my parts has a keyword tied to it and when the form is submitted the sql looks for that keyword (home1 or home2) and displays all parts with that keyword.
I'm not sure how the sql query works as I didn't write it. We used to have 2 different websites and each one had one of the forms I posted above. Now I have merged the sites together but need people to be able to search with the 2 different keywords.

hemebond
01-25-2005, 01:19 AM
With Javascript disabled, your form will crap itself. This is how I would do it
<!DOCtype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>50884</title>
</head>
<body>
<form name="find_spec" method="post" action="<*SearchResultspageURL*>">
<input type="hidden" name="find_spec" value="">
<input type="hidden" id="searchtype" name="searchtype" value="AND">


<fieldset>
<label for="location">Search within</label>
<select id="location">
<option value="home1">Home 1</option>
<option value="home2">Home 2</option>
</select>

<input id="keyword" name="keyword" type="text" size="30" maxLength="50">

<input type="submit">
</fieldset>
</form>
</body>
</html>and then parse this information server-side. If you need help doing this, post a question in the relevant forum.

price
01-25-2005, 02:48 PM
Unfortunately I don't have access to anything on the site other than what I can change through html.

hemebond
01-26-2005, 09:46 PM
<!DOCtype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>50884</title>
</head>
<body>
<script type="text/javascript">
function appendLocation()
{
document.getElementById("keyword").value += ' ' + document.getElementById("location").value;
}
</script>
<form id="find_spec" name="find_spec" method="post" action="<*SearchResultspageURL*>" onsubmit="appendLocation();">
<input type="hidden" name="find_spec" value="">
<input type="hidden" id="searchtype" name="searchtype" value="AND">


<fieldset>
<label for="location">Search within</label>
<select id="location">
<option value="home1">Home 1</option>
<option value="home2">Home 2</option>
</select>

<input id="keyword" name="keyword" type="text" size="30" maxLength="50">

<input type="submit">
</fieldset>
</form>
</body>
</html>

price
01-31-2005, 05:37 PM
That looks like what I was looking for, a script that would change it for me.

However, when I test it, it seems to be coming back "You must enter search criteria before clicking Search" as if there was an empty field :confused:

price
01-31-2005, 07:39 PM
I figured it out!!
I needed to change the text field name to "find_spec" instead of "keyword".

WORKS GREAT.

Thanks for the help Homebond!!! :thumbsup:

hemebond
01-31-2005, 09:15 PM
Thanks for the help Homebond!!! :thumbsup:Hemebond. Glad I could help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum