Solved

input type button vs image

Posted on 2014-09-10
7
224 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

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…
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 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 …

695 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