473,406 Members | 2,439 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,406 software developers and data experts.

Change Form Action with Javascript

I am trying to figure out the best way to change a form's action based
on a single text input event.

I have a search form within a larger form and would like to allow users
to use the enter key within the search text input without submitting
the larger form. I discovered the onKeyPress event and the keyCode for
the Enter Key (13). Now I need to figure out a way to pass the result
of the onKeyPress to the larger form's onSubmit event to return false
if the onKeyPress is true or allow the larger form to submit if false.

What's the easiest way to pass the onKeyPress value to the onSubmit
event?

if (event.keyCode == 13) {
document.getElementById('myform').action = "javascript: return
false;";
}

or

if (event.keyCode == 13) {
document.forms.element.hiddentextinput.value = "javascript: return
false;";
}

Thank you for your assistance.

Respectfully,
Gary

Dec 21 '05 #1
4 6487
AN************************@yahoo.com wrote:
I am trying to figure out the best way to change a form's action based
on a single text input event.


To ... "not". Have your server side form handler redirect as appropriate.

JavaScript is a fantastic tool for making life easier for users, but
depending on it isn't such a great idea.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Dec 21 '05 #2
VK

AN************************@yahoo.com wrote:
I am trying to figure out the best way to change a form's action based
on a single text input event.


If form contains only one <input type="text" element then pressing
Enter in this input leads to the form submission. This is a convenience
behavior, but if it becomes an inconvenience then you can turn it off
by using HTML only - no script needed.

Simply add another <input type="text" into your form.

Also you can use textarea instead of textfield:
<textarea name="out" cols="20" rows="1"></textarea>

Dec 21 '05 #3
VK said the following on 12/21/2005 5:59 AM:
AN************************@yahoo.com wrote:
I am trying to figure out the best way to change a form's action based
on a single text input event.

If form contains only one <input type="text" element then pressing
Enter in this input leads to the form submission. This is a convenience
behavior, but if it becomes an inconvenience then you can turn it off
by using HTML only - no script needed.

Simply add another <input type="text" into your form.


The <enter> key will still submit the form though.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '05 #4
VK

Randy Webb wrote:
The <enter> key will still submit the form though.


Only if the browser is badly borken, thus not in IE or FF. What browser
did you try?

Dec 21 '05 #5

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

Similar topics

2
by: Sylvie Stone | last post by:
Hi group - I have an html form for that uses username and password to login to a specific area of the website. The "area" the user wants to go to is based on a pull down menu. Becasue the...
4
by: Christiaan | last post by:
I am trying to create a small javascript to change the button text and then submit it and do all kinds of form validations. So I have a button with the value "Save", when the button is clicked it...
14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
34
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head>...
2
by: TJS | last post by:
in a custom control which renders a form, is there a way to define the form action other than the preset postback. I've seen several but they are all an httpModule of sorts. I would like to do...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
2
by: mcdoublev | last post by:
Hi guys, I don't know whether this is a HTML or Javascript question, but i decided to put it here. This is my problem: I am making a simple HTML form that posts a random number (generated by...
1
by: MZ | last post by:
Hello! Is it possible to change URL form action on submit form... I have tried such code: <script language="JavaScript" type="text/javascript"> function changeURL() {
6
by: Arthur | last post by:
Hello. How might it be possible to change where a form action is directed based on a selected option. For example I have this: <FORM METHOD = "post" ACTION = ""> And a drop down such as
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.