473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

add text to input

Hi there

I have an input box in a form (very simplified example below so we're
all on the same page).

<form method='post' action='http://www.theaddress.com/target.tcl'>
<input type='text' name='tb1' value=''>Search text
<input type='submit' name='action' value='Generate'>
</form>

When the user submits. I want to concatenate characters to the input
that the user typed in. Without the user knowing.

So if the user types "string", I want the form to submit "%string".

TIA
Simon
Jul 20 '05 #1
7 5624
Simon Hobbs wrote:

<form method='post' action='http://www.theaddress.com/target.tcl'>
<input type='text' name='tb1' value=''>Search text
<input type='submit' name='action' value='Generate'>
</form>

When the user submits. I want to concatenate characters to the input
that the user typed in. Without the user knowing.

So if the user types "string", I want the form to submit "%string".


That's no problem, though not part of HTML. Instead, that's server-side
scripting with a language like PHP, ASP (VBScript/ JScript), Python,
JSP, Perl, and so on. All you would need to do in e.g. PHP is to write
something like
if (!isset($tbl) { $tbl = ""; }
$tbl = "%" . $tbl;

If you do not have control over the server, or you want to submit to an
absolute URL of your partner site which is not under your control, you
can't handle the task foolproof. You might add some JavaScript, but
it's not reliable.
Jul 20 '05 #2
ge*************@hotmail.com (Simon Hobbs) writes:
I have an input box in a form (very simplified example below so we're
all on the same page).

<form method='post' action='http://www.theaddress.com/target.tcl'>
<input type='text' name='tb1' value=''>Search text
<input type='submit' name='action' value='Generate'>
</form>

When the user submits. I want to concatenate characters to the input
that the user typed in. Without the user knowing.

So if the user types "string", I want the form to submit "%string".


You need to do that on the form handler server-side. Otherwise you
can't be sure that the user won't know or that a user won't
deliberately submit one without it.

--
Chris
Jul 20 '05 #3
> > When the user submits. I want to concatenate characters to the input
that the user typed in. Without the user knowing.

So if the user types "string", I want the form to submit "%string".


You need to do that on the form handler server-side. Otherwise you
can't be sure that the user won't know or that a user won't
deliberately submit one without it.


Thanks to both posters.

I'm hiding it from the users so I don't confuse them. And so I don't
have to say: "here's what you want, except you have to type a '%' sign
before the search text". Also, I understand the value of server-side
scripting, but it is indeed a case of control, and the developers are
working on other stuff.

So it sounds like JavaScript is the go. I guess I get JS to build the
address string with all the necessary parameters and then point the
browser there? If someone can point me to an example then I should be
able to work from it. That would be cool.

S.
Jul 20 '05 #4
Oh, that was painless. I used 'onSubmit' to add the desired character
to the string and put it in a hidden textbox.

For schmucks like me, the complete html is below. Ironically, the
example uses Google and Google doesn't support wildcards.

Thanks to the poster for nudging me in the right direction.
S.

-------html below--------
<html>
<head>
<script language='JavaScript'>
<!--
function addwildcard()
{
document.f1.as_q.value = '%' + document.f1.myinput.value
}
// -->
</script>
</head>
<body>

<form method='get' action='http://www.google.com.au/search'
name='f1' onSubmit='addwildcard()'>
Keyword
<input type='text' value='' name='myinput' size='10'>
<input type='hidden' name='as_q'>
<input type='submit' name='btnG' value='Search'>
</form>

</body>
</html>
Jul 20 '05 #5
Simon Hobbs wrote:
I'm hiding it from the users so I don't confuse them. And so I don't
have to say: "here's what you want, except you have to type a '%' sign
before the search text". Also, I understand the value of server-side
scripting, but it is indeed a case of control, and the developers are
working on other stuff.


I'm guessing that you're dropping the text into a WHERE foo LIKE clause
in a SQL statement as your search mechanism. If so you may want to
either document that % and _ are wildcards or escape any user-submitted
% and _ characters before you add your own (check your DB docs for
appropriate escaping). The usual caveats about sanity-checking user
input also apply (making sure that any string-terminating characters
are escaped, etc).

Jul 20 '05 #6
Simon Hobbs wrote:
Oh, that was painless. I used 'onSubmit' to add the desired character
to the string and put it in a hidden textbox.


This will fail on browsers that do not support javascript or that have
it disabled. Doing it on the server is a much smarter plan. At least
make a note that this is going on for those users, so that searching
doesn't mysteriously Not Work for them.
Jul 20 '05 #7
Simon Wrote:
Oh, that was painless. I used 'onSubmit' to add the desired character
to the string and put it in a hidden textbox.

Owen Wrote: This will fail on browsers that do not support javascript or that have
it disabled. Doing it on the server is a much smarter plan. At least
make a note that this is going on for those users, so that searching
doesn't mysteriously Not Work for them.


Fair concern, but it's quite OK in this case. I have 50 users who use
whatever is imaged onto their laptops.

S.
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
7
by: Marios Koumides | last post by:
I post the same question few days ago but there was a confusion in the answers. Anywayz I am posting again. I have a form with 96 textboxes (8 rows x 12 columns) Now I want in the last row to have...
12
by: Randell D. | last post by:
Folks, I have a form called "ourTestForm". Its a test form - nothing special - it contains five input tags - they are named one, two, three, four and five. The input tags are of type...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
15
by: fanchun | last post by:
I already built 2 javacript files factor.js and parm.js. factor.js is an array, having several factor as elements. for example, factor.js looks like: var factor= parm.js is also an array, having...
3
by: happyse27 | last post by:
Hi All, I wanted to align the text box for user registration but the code just wont budge... Kindly advise what is wrong? Cheers... Andrew <HTML>
7
by: kirkgilbert | last post by:
I am trying to do an onchange event in a form using a text field. The form is tied to a record set that is part of a repeated region. One the first record when I edit the data it works perfectly. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.