Solved

input type button vs image

Posted on 2014-09-10
7
220 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 dynamically set the form action using jQuery.

856 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