| |

VerySource

 Forgot password?
 Register
Search
View: 628|Reply: 3

Ask an ImageButton onclick event.

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-30 20:20:01
| Show all posts |Read mode
Make a registration page. Submit button with ImageButton
But the validation form uses self-written JS. Function CheckForm ()
This way I need to call CheckForm () that JS function after pressing ImageButton.
Add ImageButton.Attributes.Add ("onclick", "return CheckForm ();") to ImageButton

CheckForm () {
if (document.getElementById ("usrname"). value.length == 0) {
alert ("username");

return false;
}
else {
return true;
}

When I press the button, the user name has an alert effect when it is empty. But return false has no effect. The page is still submitted. Refreshed once. This is the effect of using IE. But using FF is effective. It is really strange I can't figure out what's going on.
Reply

Use magic Report

0

Threads

29

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-3-8 11:45:01
| Show all posts
Attributes.Add ("onclick", "CheckForm ();")
Reply

Use magic Report

0

Threads

14

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-9 21:15:01
| Show all posts
If there is no script error on the page, it should be no problem writing in IE
Try adding event.cancelBubble = true to the function;
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-3-10 09:30:02
| Show all posts
Try it another way ~~~~
For example: try it as a button. If there is nothing wrong, it means that the imgbutton does not support javascript client events.
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