Solved

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

Posted on 2004-09-07
7
763 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now