Solved

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

Posted on 2004-09-07
7
757 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:sathishv
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
yupe :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now