Solved

input type button vs image

Posted on 2014-09-10
7
211 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 6

Author Comment

by:Robert Saylor
ID: 40315362
that worked but why do I have to give the return false?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 6

Author Comment

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now