View Full Version : using the button.click() method with image inputs
mkjohnst
10-04-2002, 08:19 PM
is it possible to use the button.click() method to simulate a click on an image input? i've tried this, but have been unable to get it to work. it works on buttons and checkboxes fine. if this is not possible, does anyone have any ideas for a workaround? Thanks... some of my code is below if it helps!
<form>
<input type="image" name="TabBudget" src="/Images/menubar_BUDGET_grey.gif">
<input type="button" value="Next" onClick="TabBudget.click()>
</form>
That's basically what I want to do. If the TabBudget object is a regular button there doesn't seem to be a problem, but I would rather not do it that way because of some coding issues with the database it is interacting with.
Mike
eoincunningham
10-04-2002, 08:28 PM
You don't have an inverted comma after click()
mkjohnst
10-04-2002, 08:32 PM
Ah, my apologies. I have one in my code, but I didn't want to include the entire file so I retyped the relevant portion and forgot the semicolon and quotation mark.
<form>
<input type="image" name="TabBudget" src="/Images/menubar_BUDGET_grey.gif">
<input type="button" value="Next" onClick="TabBudget.click();">
</form>
eoincunningham
10-04-2002, 08:41 PM
I'm not sure. Maybe if you reference it by its full name, which I think would be:
window.document.forms["FORMNAME"].TabBudget.click();
Incidentally, your question helped me figure out a similar problem I needed for work, so thank you.
mkjohnst
10-04-2002, 08:50 PM
Good suggestion, but I don't seem to be having any luck putting things explicitly... it still won't call a click on that image input. Please pass any other ideas you have along! :) Thanks,
Mike
eoincunningham
10-04-2002, 09:51 PM
It turns out that I now also need to know how to simulate a click on an image. I'll let you know if I find out anything.
adios
10-04-2002, 10:49 PM
<html>
<head>
<title>untitled</title>
</head>
<body>
<form onsubmit="alert('submitted')">
<input type="image" id="TabBudget" src="http://www.codingforums.com/images/reply.gif">
<input type="button" value="Next" onclick="document.getElementById('TabBudget').click()">
</form>
</body>
</html>
This one is really odd. <input type="image"> is supposed to be a legitimate form element - but it appears to not be a form element at all! In the above, onclick="alert(this.form.elements[0].type)" alerts 'button' - the image submit isn't in the collection - surprisingly, "alert(document.images[0])" yields 'undefined'. Where the heck is it? The above is the only thing I could get to work (didn't try DOM traversing). Strange. If you make it an ordinary <img>, works fine.
More details: http://www.cs.tut.fi/~jkorpela/forms/imagebutton.html
mkjohnst
10-04-2002, 11:21 PM
Wow! Thanks so much for the help!! I was baffled.... I'm new to JavaScript but this seemed really strange. Thanks for helping me clear it up.
Mike
eoincunningham
10-07-2002, 07:06 PM
I was able to get mine working in the end by taking a different approach. I had wanted to make it click on the image to submit the form. Instead, I just made the form submit by calling it this way.
window.document.forms["FORMNAME"].submit();
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.