Solved

input type button vs image

Posted on 2014-09-10
7
217 Views
Last Modified: 2014-09-10
When I use a input type = button with a onclick event it works. When I use a image it does not. What is the difference?

Works
<input type="button" value="Login" onclick="login(this.form)">

Open in new window


Does Not Work
<input type="image" src="buttons/bt-login.png" onclick="login(this.form)">

Open in new window


                                <script>
                                function login(myform) {
                                        $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                          if (php_msg.substring(0,5) == "https") {
                                             $("#login-scr").html('<span class="details-description"><br><font color=green>Login successfull. Loading please wait...</font><br></span>');
                                             setTimeout(function()
                                                {
                                                window.location.replace(php_msg)
                                                }
                                             ,2000);
                                          } else {
                                             $("#login-scr").html(php_msg);
                                          }
                                        });
                                }
                                </script>

Open in new window

0
Comment
Question by:Robert Saylor
  • 3
  • 2
  • 2
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 40315342
use : <input type="image" src="buttons/bt-login.png" onclick="login(this.form); return false;">
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40315347
or :
<input type="image" src="buttons/bt-login.png" id="but" />

<script>
jQuery(function($) { // same as $(document).ready(function() {
      $("#but").click(function(evt) {
    evt.preventDefault();
    var myform = $(this).closest("form");
    $.get('login.php',
                                        $(myform).serialize(),
                                        function(php_msg) {
                                          if (php_msg.substring(0,5) == "https") {
                                             $("#login-scr").html('<span class="details-description"><br><font color=green>Login successfull. Loading please wait...</font><br></span>');
                                             setTimeout(function()
                                                {
                                                window.location.replace(php_msg)
                                                }
                                             ,2000);
                                          } else {
                                             $("#login-scr").html(php_msg);
                                          }
                                        });
      });
});
</script>

Open in new window

0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 40315362
that worked but why do I have to give the return false?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 40315369
input type="image"
is the "same" as
input type="submit"

(no points for this)
0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 40315374
ah, thanks that makes since to me now :)
0
 
LVL 7

Author Closing Comment

by:Robert Saylor
ID: 40315380
Thanks guys you saved my CSS designer from having to create button classes lol.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40315389
Ermm I said no points.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question