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

Form with two submit buttons

ak1dnar
1,584 Expert 1GB
I need to print A when click on Button A and and print B for button B.
but for both button it gives A.
[HTML]<html>
<head>
<script language="JavaScript" type="text/javascript">
function AB()
{
if(document.testform.btn_a)
{
alert("A");
return false;
}
if(document.testform.btn_b)
{
alert("B");
return false;
}
}
</script>

</head>

<body>
<form action="next.php" method="post" name="testform" onsubmit="return AB();">
<input name="btn_a" type="submit" value=" A " />
<input name="btn_b" type="submit" value=" B " />
</form>
</body>
</html>
[/HTML]
May 9 '07 #1
3 1500
acoder
16,027 Expert Mod 8TB
Are you going to submit the form to a server script (Is the return false just for testing)? Usually you can use the server-side language to detect which button has been clicked.

You're checking for btn_a which exists so it will always return true. Try using onclick and setting a variable to 'a' or 'b', then testing for that in the onsubmit.
May 9 '07 #2
ak1dnar
1,584 Expert 1GB
Yes this is for testing only.
in my actual form there are two submit buttons. and there is a server side script.

for submit_1 the number of rows will update with the server side script.
for submit_2 the form content(User Details) will pass to the same script for processing.(Except number of rows text input).

that is working fine.

but when submit User details (Not the row numbers) i need to run the JS to validate user inputs. the problem is for for rows updating button also the JS is executing.
May 10 '07 #3
pbmods
5,821 Expert 4TB
but when submit User details (Not the row numbers) i need to run the JS to validate user inputs. the problem is for for rows updating button also the JS is executing.
Try making the form action your validation function instead. See this post:
http://www.thescripts.com/forum/thread636859.html
May 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jason | last post by:
Is it possible to POST a FORM to multiple URLS at the same time....OR.... Is the only workaround for this scenario to use response.redirect in the called ASP page and do a multi processing? -...
1
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p...
2
by: Matt | last post by:
The problem is I have 3 buttons that need to submit the form to different URL. My approach is to declare <input type="submit"> rather than <input type="button">. And put the following in the...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
1
by: Matt | last post by:
The problem is I have 3 buttons that need to submit the form to different URL. My approach is to declare <input type="submit"> rather than <input type="button">. And put the following in the...
2
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
3
by: M | last post by:
i am using submit buttons to send the user to different parts of a wizard. i am using if (if attribute.step1 exists) statements to send them to the appropriate section based on which submit button...
4
by: wim taerwe | last post by:
Hello, I am looking for an easy way to have a delete button per subitem in 1 form. For example : a book can have many authors and when I edit the book details I want to have a list of the...
5
by: zoomcart.com | last post by:
Hello and thanks in advance for your help. I have code below that posts form data to a cgi scripted shopping cart and it works great on my mac/firefox browser, but it doesn't work on ibm/netscape...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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.