473,573 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Easy question...

I'm new to javascript. I have a form with 2 buttons. I want an alert
to show what button was clicked. Also, is there a way to prevent the
text fields from disappearing after submitting a form? Thanks... CM

<SCRIPT LANGUAGE="JavaS cript">
function picked()
{
if(login.value= ="1")
{
alert("Yes");
}
if(login.value= ="2")
{
alert("No");
}
}
</script>

<form onsubmit="picke d()">
<input type="submit" name="login" value="1">
<input type="submit" name="login" value="2">
</form>

Feb 8 '06 #1
5 978
TJO
<input type="submit" name="login" value="1" onclick="picked ()">

Feb 8 '06 #2
wrote on 08 feb 2006 in comp.lang.javas cript:
I'm new to javascript. I have a form with 2 buttons. I want an alert
to show what button was clicked. Also, is there a way to prevent the
text fields from disappearing after submitting a form? Thanks... CM

<SCRIPT LANGUAGE="JavaS cript">
function picked()
{
if(login.value= ="1")
{
alert("Yes");
}
if(login.value= ="2")
{
alert("No");
}
}
</script>

<form onsubmit="picke d()">
<input type="submit" name="login" value="1">
<input type="submit" name="login" value="2">
</form>


<script type="text/javascript">
function picked(x) {
if(x.value==1)
alert("One");
else
alert("Two");
return false;
}
</script>

<form>
<input type="submit" onclick='return picked(this)' value="1">
<input type="submit" onclick='return picked(this)' value="2">
</form>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 8 '06 #3

mo*****@yahoo.c om wrote:
I'm new to javascript. I have a form with 2 buttons. I want an alert
to show what button was clicked.
The solution given by Evertjan will solve your problem.
Also, is there a way to prevent the
text fields from disappearing after submitting a form? Thanks... CM
You are submitting a form. If you don't want your form to "disappear" ,
I can think of 3 ways.

1. Submit the form (postback) to the current page, then fill out the
form.
2. Perhaps a form is not what you really need.
3. Use XMLHttpRequest to submit the form.
<input type="submit" name="login" value="1">
<input type="submit" name="login" value="2">


Was it intentional to have two submit buttons?

Feb 8 '06 #4
Thanks for your help guys... CM

Feb 9 '06 #5
web.dev said the following on 2/8/2006 6:46 PM:
mo*****@yahoo.c om wrote:
I'm new to javascript. I have a form with 2 buttons. I want an alert
to show what button was clicked.
The solution given by Evertjan will solve your problem.
Also, is there a way to prevent the
text fields from disappearing after submitting a form? Thanks... CM


You are submitting a form. If you don't want your form to "disappear" ,
I can think of 3 ways.

1. Submit the form (postback) to the current page, then fill out the
form.


Or submit it to a hidden IFrame.
2. Perhaps a form is not what you really need.
3. Use XMLHttpRequest to submit the form.


Thats the *last* way one should submit a form.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 9 '06 #6

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

Similar topics

1
2213
by: rdsteph | last post by:
I am having a lot of fun using the pyGoogle module ( http://pygoogle.sourceforge.net/ ) that uses the Google API. It is about as easy to use as I can imagine, and it is a lot nicer than using my old HTMl screen scraping habits. My online CGI program Ask Merlin at www.awaretek.com/askmerlin.html is an example. Currently, the program takes...
0
1364
by: | last post by:
I don't know SQL at all, but I have a problem now because I must use SQL in my PHP scripts. So please help me! I have 2 tables: id | name ----------- 1 | thing1 2 | thing2 3 | thing3 4 | thing4
5
1521
by: LedZep | last post by:
What up, All I need to do is enter a last name in a text box, query a MSAccess database and display the name with the corresponding columns. This is no problem, but when there are more than one records with the same last name, I need to click a command button to display the next record with that name. I cant find it in any of my books and...
1
4930
by: Mad Scientist Jr | last post by:
can someone explain how to simply populate a grid in .net ? the way i understand it, there is no more msflexgrid, and instead is this new control that has to be tied to a dataset, and it is a real pain to work with if you just want to throw some values in a grid and edit them with a textbox. i don't want to persist anything in a database, i...
13
1472
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. : MyApp.exe "Go"
1
1475
by: melanieab | last post by:
Hi, If there's a textbox and the text entered is longer than what's visible (the textbox length), how do you make it so that the beginning chunk of text is visible (instead of the last part of it)? Thanks again!!! Mel
23
2408
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
6
2283
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double (*f)(float)" But I want to be able to pass a
27
2267
by: smnoff | last post by:
How does( or should user use) strncpy() to allocate enough memory space for the destination string, s1? I guess I am having trouble using strncpy as it seems to be giving me errors. And just as well, I don't know the value of n until the program runs, so it needs to be dynamically allocated. Then again I hard coded n to be number like3...
9
1886
by: rynTAU | last post by:
This is an easy question, I'm sure but I can't seem to figure it out. I'm trying to use the number_format() function to remove all decimal places from a number. $num = number_format($num, 0, '.', ''); So if I have 23.34567 I want 23, and 45.8789 will return with 45.
0
7778
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7777
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...
0
8063
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...
0
6413
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...
1
5585
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...
0
3731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2203
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
1300
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.