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
kenabbottAsked:
Who is Participating?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

try
<form method="get" action="" name="test" onsubmit="return Reload()"/>
0
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.