473,569 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image type button not starting javascript action

This works:
<input type="button" value="Add to list" onClick="addOpt ion(param1,
param2);">

But this doesn't:
<img src="images/add.gif" onClick="addOpt ion(param1, param2);">

The error I get using the img tag is, "this.form has no properties". Yet it
is right beside the input tag that does work with the same OnClick= params

This doesn't work either:
<input type="image" src="images/add.gif" value="Add to list"
onClick="addOpt ion(param1, param2);">

The error I get with this is that it does the javascript action then Submits
the form - I do not want it to submit, just do the javascript action.

What can I do to get a graphic button that will complete the javascript
action?

Thanks!
Aug 7 '06 #1
4 1906
Notgiven wrote:
>This doesn't work either:
<input type="image" src="images/add.gif" value="Add to list" onClick="addOpt ion(param1, param2);"

The error I get with this is that it does the javascript action then Submits
the form - I do not want it to submit, just do the javascript action.
try

onClick="addOpt ion(param1, param2);return( false);"
Michael

Aug 7 '06 #2
Notgiven said the following on 8/7/2006 3:50 PM:
This works:
<input type="button" value="Add to list" onClick="addOpt ion(param1,
param2);">

But this doesn't:
<img src="images/add.gif" onClick="addOpt ion(param1, param2);">

The error I get using the img tag is, "this.form has no properties". Yet it
is right beside the input tag that does work with the same OnClick= params
That is because img elements are not part of the form so when you try to
refer to this.form you get the error.
This doesn't work either:
<input type="image" src="images/add.gif" value="Add to list"
onClick="addOpt ion(param1, param2);">

The error I get with this is that it does the javascript action then Submits
the form - I do not want it to submit, just do the javascript action.
That is because the default behavior for input type="image" is to submit
the form.
What can I do to get a graphic button that will complete the javascript
action?
Pass a reference to your form to the function.

function addOption(formR ef,param,param2 ){

}

onclick="addOpt ion('document.m yForm',param1,p aram2)"

Or something similar. Without seeing your function it is *impossible* to
give a definitive answer

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 7 '06 #3
Michael A. Vickers said the following on 8/7/2006 3:57 PM:
Notgiven wrote:
>This doesn't work either:
<input type="image" src="images/add.gif" value="Add to list" onClick="addOpt ion(param1, param2);"

The error I get with this is that it does the javascript action then Submits
the form - I do not want it to submit, just do the javascript action.

try

onClick="addOpt ion(param1, param2);return( false);"
return(false)?

return isn't a function, drop the parentheses:

return false

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 7 '06 #4
"Randy Webb" <Hi************ @aol.comwrote in message
news:0Y******** *************** *******@comcast .com...
Notgiven said the following on 8/7/2006 3:50 PM:
>This works:
<input type="button" value="Add to list" onClick="addOpt ion(param1,
param2);">

But this doesn't:
<img src="images/add.gif" onClick="addOpt ion(param1, param2);">

The error I get using the img tag is, "this.form has no properties". Yet
it is right beside the input tag that does work with the same OnClick=
params

That is because img elements are not part of the form so when you try to
refer to this.form you get the error.
>This doesn't work either:
<input type="image" src="images/add.gif" value="Add to list"
onClick="addOp tion(param1, param2);">

The error I get with this is that it does the javascript action then
Submits the form - I do not want it to submit, just do the javascript
action.

That is because the default behavior for input type="image" is to submit
the form.
>What can I do to get a graphic button that will complete the javascript
action?

Pass a reference to your form to the function.

function addOption(formR ef,param,param2 ){

}

onclick="addOpt ion('document.m yForm',param1,p aram2)"

Or something similar. Without seeing your function it is *impossible* to
give a definitive answer

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
Randy - that worked perfectly - many thanks!
Aug 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
11487
by: Ryan | last post by:
I currently have two image submit buttons. The code generated looks like so: <input type="image" src="button_in_cart.gif" border="0" alt="Add" title="Add" name="btn_cart" value="buy"> <input type="image" src="modify.gif" border="0" alt="modify" title="modify" name="btn_modify" value="modify"> In mozilla everything works great, but in...
1
18771
by: Jawahar Rajan | last post by:
All, I am using a few Input type of "Image" instead of a classic submit button in a form to achieve various tasks for example image1 - add user image2 - modify user image3 - delete user image4 - reSet user.
3
7150
by: bigoxygen | last post by:
Hi. I have a list that is similar to this: -Evaluation +test +test -Students +test I would like to change the "-" bullet only, but I cannot. My
1
3034
by: Dave | last post by:
Hi all, I was trying to make an image submit button with a rollover and discovered to my suprise that there is no way to access a form element of the "image" type. I tried specifying it by name and also by the elements array with no luck. Even weirder, I can sandwich an image button in between other input types and then write a script...
2
3489
by: Matt | last post by:
In the following code, I have 2 questions regarding submit button with image. 1) Does this code <input type="image" name="populate" src="populate.gif"> behave the same as an HTML submit button with image populate.gif? When I click p1 or p2 button, it will post the page to process.asp. 2) When I check the checkbox, I want the image in...
3
21248
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image' src='picture.gif' name='myimage' id='myimage'> </form> When forms with image types are submitted, the value is not returned; instead, when the form is submitted,...
16
2846
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the ass and the app will be used internally so I'm not too worried about users who aren't using javascript. I'm using the following javascript to detect...
2
2355
by: Poppa Pimp | last post by:
ImageResizer.php Image Resizer PLEASE HELP The URL of the page this is on in my site is http://poppa-pimps-wallpapers.com//ImageResizer.php You can click on browse and get image,but when you upload image it will go to another page and says ]((unable to create emp directory)) Here is a site to be able to see script actually work...
4
2698
by: yatin | last post by:
hi, friend. i have a problem in image validation plz check it. i have to include a image validation in foam 1. but i sending a details through form2. But when i include a image validation in foam1, then i can not change my image on calling a function onchange="return valid1" <my source code is here> <? session_start(); ob_start();...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.