?
Solved

input type button vs image

Posted on 2014-09-10
7
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 58

Assisted Solution

by:Gary
Gary earned 1000 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

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 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