473,320 Members | 2,189 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.

Form sending the user to an arbitrary url

<html>
<head>
<script type="text/javascript">
function submit() {
var queryField = document.getElementById("queryField");
document.location.href = document.location.href + "/query/" +
queryField.value;
return false;
}
</script>
</head>
<body>
<form onsubmit="return submit();">
<input name="query" id="queryField">
<input type="submit">
</form>
</body>
</html>

This is my script/HTML page. I am just trying to do this:

The user goes to www.mysite.com. There is an input box and a submit
button. They enter text into the input box (ie "john") and hit submit.
I now want to redirect them to www.mysite.com/query/john instead of
www.mysite.com/?query=john. I thought this script would do it but it
does not.

I think it is something to do with the onsubmit= thing. Because this
has worked if I just trap onclick on the button. But then if you press
return/enter on the search field it will not work. Any ideas?

Thanks in advance.
-Steve

Jul 23 '05 #1
1 1182
It happens www.mysite.com/?query=john when you use form and submit
button.

Try this one

<html>
<head>
<script type="text/javascript">
function submit() {
path = "http://www.mysite.com/query/";
location.href = path + query.value;
}
</script>
</head>

<body>
<input type="text" name="query" /> <input type="button"
onclick="submit();" value="Submit" />
</body>
</html>

Sujan

Jul 23 '05 #2

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
1
by: Jim Tome | last post by:
Hello, I'm not much of a Perl programmer (I usually just adapt a canned formmail script!), but I have a situation where I need to route information from an HTML contact form to different people...
5
by: Wes | last post by:
Apparently some of our form users are trying to add new lines in a text field and are hitting the <enter> key thus causing the form to be submitted prematurely. There is no algorithm we can write...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
13
by: johnemmatty | last post by:
I am using an asp page in which i dynamically fill the ACTION property of the form. The problem is that whenever i try to redirect to a html page using the javascript:location, it is getting...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
0
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.