Easy question...

M

mouac01

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="JavaScript">
function picked()
{
if(login.value=="1")
{
alert("Yes");
}
if(login.value=="2")
{
alert("No");
}
}
</script>

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

Evertjan.

wrote on 08 feb 2006 in comp.lang.javascript:
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="JavaScript">
function picked()
{
if(login.value=="1")
{
alert("Yes");
}
if(login.value=="2")
{
alert("No");
}
}
</script>

<form onsubmit="picked()">
<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>
 
W

web.dev

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?
 
R

Randy Webb

web.dev said the following on 2/8/2006 6:46 PM:
The solution given by Evertjan will solve your problem.


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,129
Messages
2,570,763
Members
47,324
Latest member
RicoBoxer

Latest Threads

Top