• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

input type image problem

Hi

I am having a problem using <input type="image" to call a javascript function in a PHP page.

The function is...

-----------------------------------

function Reload() {      

//form validation
      
      
      if (LOn == 0) {
            alert("Please Choose a Level!")
      return;
      }
      
      if (POn == 0) {
            alert("Please Choose a Program!")
      return;
      }

      var url = 'Selection.php?inputValue='+ChosenLevel+'='+ChosenProg;
      location.href=url;

}

-----------------------------------

The variables are globals

If I use...

<input type="button" name="Go" value="Go" onclick = "Reload()"/>

... it works fine

However if I use...

input type="image" src="Images/ButtonDisplay.jpg" name="Go2" onclick = "Reload()"/>

... it doesn't

The latter example seems to call the function but it won't refresh the page.  The function must be fine because it works perfectly with the <input type="button" code

Ani ideas??

Many thanks
0
kenabbott
Asked:
kenabbott
  • 3
  • 2
  • 2
  • +3
3 Solutions
 
GawaiCommented:
The <input type="image" /> tag creates submit buttons using images.

and the
<input type="button" name="Go" value="Go" onclick = "Reload()"/>
is not the submit button. thats the main diff.
0
 
Kiran Paul VJComputer EngineerCommented:
which browser are you using, i checked the above code in IE6 and FF, its working fine.

can you add

      alert("function test");
      return true;

in top of the function and check if it shows alert

kiranvj
0
 
GawaiCommented:
if your code doest not work onclick of input type

try
<form method="get" action="" name="test" onsubmit="return Reload()"/>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kenabbottAuthor Commented:
I could use the form resumbit but I would rather find why the code isn't working
0
 
Kiran Paul VJComputer EngineerCommented:
hi,

the code is working fine, but not rather like you thought.

This is how it works if you use type=input

calls Reload(), and changes the location to the address in url variable.

when type is image

calls Reload(), and changes the location to the address in url variable. Then submits form, which loads the same page again. Because as gawai said eariler the type="image" acts like a submit button
0
 
kenabbottAuthor Commented:
Thanks - is there any easy way around this??
0
 
Kiran Paul VJComputer EngineerCommented:
yes,
either you use <img src="Images/ButtonDisplay.jpg" name="Go2" onclick = "Reload()"/> instead of <input type="image" src="Images/ButtonDisplay.jpg" name="Go2" onclick = "Reload()"/>

or as gawai mentioned earlier you can use something like

<form method="post" action="" name="test" onsubmit="return Reload()"/>

with

function Reload() {      

//form validation
     
      if (LOn == 0) {
            alert("Please Choose a Level!")
      return false;
      }
     
      if (POn == 0) {
            alert("Please Choose a Program!")
      return false;
      }

      var url = 'Selection.php?inputValue='+ChosenLevel+'='+ChosenProg;
      location.href=url;
     return false;

}
0
 
gops1Commented:
As gawai suggested input type image creates submit button. If you want to use image why cant you use anchor tag.

<a href="#" name="Go2" onclick = "Reload();return false;"><img src="Images/ButtonDisplay.jpg"></a>
0
 
DiscoNovaCommented:
K.I.S.S.

<input type="image" src="Images/ButtonDisplay.jpg" name="Go2" onclick = "Reload();return false;"/>
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now