Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Changing the "onsubmit" in a form?

    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?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable, form processing

    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.
    Regards,
    Ronald.
    ronaldvanderwijden.com

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    With Javascript disabled, your form will crap itself. This is how I would do it
    Code:
    <!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.

  • #5
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Unfortunately I don't have access to anything on the site other than what I can change through html.

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!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>

  • #7
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!!!

  • #9
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by price
    Thanks for the help Homebond!!!
    Hemebond. Glad I could help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •