473,626 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById('myfor m').action = "javascript : return
false;";
}

or

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

Thank you for your assistance.

Respectfully,
Gary

Dec 21 '05 #1
4 6502
AN************* ***********@yah oo.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************* ***********@yah oo.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************* ***********@yah oo.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.javas cript 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
11430
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 user/password info is in differnet databases, how can I call different validation scripts based on this input ? THANK YOU! See below please. Somethinglike this:
4
3606
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 should change into "Are you sure" and when you then click the button the form must be submitted. I know this is possible using a simple dialog box but I want to this it this way. This is what I already have, if you have any suggestions please...
14
2484
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 change its text contents from a link elsewhere in the page? I have a rought idea that I'll need something like 'id' in my <td> tags but while I have a greater understanding of server-side programming langauges like PHP, javascript is still very new...
34
4895
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> <title>Test</title> </head> <body> <form method="post" action="javascript:">
2
2018
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 it at the page or control level if possible. thanks
10
6072
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
2
22004
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 Javascript) on my website, but I'm having trouble assigning the random number to the form. This is what I have right now:
1
21863
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
19141
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
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.