Solved

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

Posted on 2004-09-07
7
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

728 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