| |

VerySource

 Forgot password?
 Register
Search
View: 1308|Reply: 8

Solve a small problem ?!

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-7 13:40:01
| Show all posts |Read mode
There are two submit (submit1, submit2) in a form, I want to identify which submit was pressed when submitting, (determined in onsubmit);
Please enlighten me, thank you!
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-7 20:18:01
| Show all posts
2 forms such as
form1 and form2 can write events in onsubmit
example
<form id = form1 onsubmit = "alert ('form1 submit')">
<input id = "b1" type = submit value = "button1">
</ form>
<form id = form2 onsubmit = "alert ('form2 submit')">
<input id = "b2" type = submit value = "button2">
</ form>
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-8 09:09:01
| Show all posts
alert (event.srcElement.value)
Reply

Use magic Report

1

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-8 12:54:01
| Show all posts
Learn.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-8 13:00:02
| Show all posts
to疯狂的兔子: Thank you, this is an alternative solution, haha
Reply

Use magic Report

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-13 14:54:01
| Show all posts
Why am I not allowed to write two forms when writing a page? Haha, depressed
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-13 16:45:01
| Show all posts
Don't be the same as NAME
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-21 02:09:02
| Show all posts
<form>
<input type = "submit" value = "button1" onclick = "alert ('BTN1');">
<input type = "submit" value = "button2" onclick = "alert ('BTN2');">
</ form>

Form submission, onsubmit take srcElemnt is the form itself
Or write a method on the button's onclick
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-27 00:09:01
| Show all posts
If it's the button's OnClick event, use event.srcElement.id to get the ID of the button clicked
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list