Solved

Prepend a word in an HTML <input> field upon Submit

Posted on 2004-09-07
7
778 Views
Last Modified: 2012-06-21
On a site I'm working on, we use Atomz' free search. If you're not familiar with Atomz, they supply the code for your site's search form, which you paste into your HTML. Each field has an atomz-specific code in addition to regular HTML, when the form is submitted it gets sent to atomz' server, and the code is matched to your site's index there.

I asked atomz how to tweak the form to force a particular type of search (instead of relying on users to follow instructions regarding which search options to turn on and off) and they told me exactly how, except for one thing, which they said I'd need to write some javascript for.

And that's why I'm posting this here...

They said I'd need to use javascript to "automatically prepend a search term to the sp-q parameter". What they're talking about is their code in the search term input field:

<b>Search For:</b><br>
<input size=35 name="sp-q">
<!-- The "Search" button -->
<input type=submit value="Search">

So the name for the search term field is "sp-q".

What I want to do is, whatever the person enters in the Search field, to be preceded by the word "Archives" when they click the Submit button.

So if they enter "product info" the actual search term that Atomz gets is "Archives product info", like that.

If I could figure out a way for javascript to do this, then (combined with a few other tweaks) I could force searches to be confined to certain folders... something that atomz normally charges hundreds of dollars for. ;-)

Whoever answers, could you also tell me *where* in the html page I should put the javascript ... before the initial <form> field? or inside the form, before the Submit button part?

thx
HG
0
Comment
Question by:hergeekness
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Assisted Solution

by:sathishv
sathishv earned 150 total points
ID: 11996965
Add it to the onsubmit event of the form.

<form onSubmit="document.forname.sp-q.value='Archives '+document.forname.sp-q.value;">

Hope this helps.

Cheers,
Sathish
0
 
LVL 14

Accepted Solution

by:
boonleng earned 150 total points
ID: 11996999
Similar one:

<form onsubmit="this['sp-q'].value='Archives ' + this['sp-q'].value">
<b>Search For:</b><br>
<input size=35 name="sp-q">
<!-- The "Search" button -->
<input type=submit value="Search">
</form>
0
 
LVL 4

Author Comment

by:hergeekness
ID: 11997226
sathishy, currently the form doesn't have a name (that's what you mean by "document.fornam" I assume) ... I could name it of course, hopefully that won't screw up atomz (like I said I just pasted in their code).

boonleng and sathisy, you're both suggesting I add stuff to the initial form tag. Right now it says:

<form method="get" action="http://search.atomz.com/search/">

Would I add the "onSubmit" part after the action in the same tag?

<form method="get" action="http://search.atomz.com/search/" onsubmit="this['sp-q'].value='Archives ' + this['sp-q'].value">

like that?

hg

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 6

Expert Comment

by:sathishv
ID: 11997260
You can do it either way. And adding a name to the form tag shouldn't affect other code.
0
 
LVL 4

Author Comment

by:hergeekness
ID: 11997722
thanks. I won't be able to try either of these until I finish some other stuff, but I trust you :-)

I'll split the points since it sounds like either way will work (and I'll bump up the point value a bit).

hg
0
 
LVL 4

Author Comment

by:hergeekness
ID: 11997755
wait ... just want to confirm that I add the javascript inside the same form tag as the method and action ... right?

hg
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12002606
yupe :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get javascript video player button to work 10 23
Javascript Regex 7 20
15 puzzle in Javascript/html 2 44
Scroll 5 news at a time using vticker 2 12
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question