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
Solved

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

Posted on 2004-09-07
7
772 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

809 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