Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image button won't send value

Status
Not open for further replies.

thunderain

Programmer
Jan 10, 2002
40
0
0
CA
This should have a simple solution. My form submit button works fine if I use type="submit", it sends the value of "View" just fine.

<input type=&quot;submit&quot; name=&quot;btnView&quot; value=&quot;View&quot;>

However I need to use and image. When I use the line below, it does not send the value of &quot;View&quot;.

<input type=&quot;image&quot; src=&quot;c:\inetpub\ name=&quot;btnView&quot; value=&quot;View&quot;>

I also tried this line, which also does not return the value of &quot;View&quot;

<button type=&quot;submit&quot; name=&quot;btnView&quot; value=&quot;View&quot;><img src=&quot;c:\inetpub\
Can anyone tell me how to send the value with an image button instead of a submit button.

Thank you
Thunderain
 
Change this...

Code:
<input type=&quot;image&quot; src=&quot;c:\inetpub\[URL unfurl="true"]wwwroot\autovu\icons\view.gif&quot;[/URL]  name=&quot;btnView&quot; value=&quot;View&quot;>

to this

Code:
<input type=&quot;image&quot; src=&quot;c:\inetpub\[URL unfurl="true"]wwwroot\autovu\icons\view.gif&quot;[/URL]  name=&quot;btnView&quot; onClick=&quot;formname.Submit();&quot; value=&quot;View&quot;>
where formname is the name/id of the form you are submitting.
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thanks for the help Rob. I put in a form name with the onClick as below, but it still isn't sending a value. Any other ideas?

<form method='post' ACTION='buttonchoice.asp' name='customerform'>

<input type=&quot;image&quot; src=&quot;c:\inetpub\ name=&quot;btnView&quot;
onClick=&quot;customerform.Submit();&quot; value=&quot;View&quot;>

thanx
thunderain
 
Hi,

Silly question, but you did remember to put the </form> tag in?

James
 
Hi,

Or even a return false bit at the end, I would test it out, but I dont have ASP ability on this machine :-(

James
 
Whats this name=&quot;btnView&quot; ??

I use simply:

<input type=image name=&quot;SUBMIT&quot; src=&quot;your-img.gif&quot; border=&quot;0&quot; alt=&quot;Login!&quot;>

and it works everytime!

É
 
Hi thunderain,

I looked in my books and on some sites, but there is no
such thing as a value attribute for <input type=&quot;image&quot; ...>
I even looked in it up in the HTML 4.0 specifications but
it's just not there. So what I think you should do is to
use a JavaScript and subtract the button name since it does
send that along with the co-ordinates of where the user
clicked. By doing that you can still determine which
button had send the info. You could use a javascript for
that, by using something like this :

<form name=&quot;MyFormWithMyStuff&quot; action=&quot;buttonchoice.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;SendBy&quot;>
... bla bla bla whatever bla bla bla ...
</form>

<script language=&quot;JavaScript&quot;>
<!--
var start = self.location.href;
var startpos = start.lastIndexOf('&');
var endpos = start.lastIndexOf('.');
var buttonpressed = start.substring(startpos+1,endpos);
MyFormWithMyStuff.SendBy.value = buttonpressed;
//-->
</script>


With this script you can store it (the extracted button
name) in the hidden field &quot;SendBy&quot; on the
form &quot;MyFormWithMyStuff&quot;. I hope you can use this. If you
can use it, it needs to be put into &quot;buttonchoice.asp&quot; It
is adviseable to make this script the VERY LAST thing on
your page, just to make sure that the object that you want
to put these value('s) in are loaded.

Alteratively, you can use the onClick-event to write a value
to a hidden field and then just submit as normal.
Something like this, on the submit form:

<form name=&quot;MyFormToSubmit&quot; action=&quot;buttonchoice.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;chosenbutton&quot;>
<input type=&quot;image&quot; name=&quot;view1&quot; src=&quot;view1.gif&quot; onClick=&quot;MyFormToSubmit.chosenbutton.value = 'View';&quot;>
<input type=&quot;image&quot; name=&quot;view2&quot; src=&quot;view2.gif&quot; onClick=&quot;MyFormToSubmit.chosenbutton.value = 'Look';&quot;>
<input type=&quot;image&quot; name=&quot;view3&quot; src=&quot;view3.gif&quot; onClick=&quot;MyFormToSubmit.chosenbutton.value = 'See';&quot;>
<input type=&quot;image&quot; name=&quot;view4&quot; src=&quot;view4.gif&quot; onClick=&quot;MyFormToSubmit.chosenbutton.value = 'Sight';&quot;>
</form>

This solution makes an extra field being send along,
carrying the pressed button value. I hope you find this
usefull.

Good luck, BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Thanks for the help guys, but it is still a problem.

James: Yes I do have a </form> tag in the right place. I have several other buttons on the page that do not need to send a value, and they work just fine with images. I am really not sure as to what you mean by &quot;return a false bit at the end&quot;. Can you elaborate or give example? Thank you

Cian: Yes your example works fine (it is not sending a value) as I said I have other buttons without sending a value as you have in your example and they work just fine. But for 2 of my buttons i MUST send a value. (As i said, even these work fine if I substitute the ugly grey submit buttons, but when putting in the image buttons, it will not send the value.). I did change the name from btnView to submit for test, but it didn't make a differnce.

Wow, i thought this would be a simple quick fix.

Thanks for help, any more suggestions?
thunderain
 
Whats wrong with two suggestions, they work just fine ...
Although the in both case the value isnt send by the button
itself, the value does arrive and can be used ... BobbaFet

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Sorry I missed that thing about sending values.
My site is down so I cant play with options. Did you try just adding value=&quot;&quot; to the line I gave you? U probably did, no help from me! :(

Hope u find a solution. Try Bobbafets,

É
 
Try this in your buttonchoice.asp (The image x is just a blank image):

<%
strAction = request.form(&quot;btnView.x&quot;).item
if strAction <> &quot;&quot; then
strAction = &quot;View&quot;
else
strAction = request.form(&quot;btnView&quot;).item
end if

if strAction = &quot;View&quot; then
....your code....
end if

%>

<form method=&quot;post&quot; ACTION=&quot;buttonchoice.asp&quot; name=&quot;customerform&quot;>
<img src=&quot;/autovu/icons/x.gif&quot; width=&quot;1&quot; height=&quot;4&quot; border=&quot;0&quot;><br>
<input type=&quot;Image&quot; src=&quot;/autovu/icons/icons\view.gif&quot; name=&quot;btnView&quot; onclick=&quot;submit();&quot; border=&quot;0&quot;>

<input type=&quot;Submit&quot; name=&quot;btnView&quot; value=&quot;View&quot;>
</form>

In this way you can ask your action or button if you want! You don't have to have a value at the image TAG!
 
Just make it sure that your that the button image you have is inside in your form.

This one is ASP.

<form action=&quot;form_submit.asp&quot; method=&quot;get&quot;>
<table>
</tr>
<td>
<input TYPE=&quot;image&quot; SRC=&quot;images/submit_button.gif&quot;
BORDER=&quot;0&quot; WIDTH=&quot;65&quot; HEIGHT=&quot;23&quot;>
</td>
</tr>
</table>
</form>

This one is CGI-bin.
<FORM action=&quot; method=post>
<table>
</tr>
<td>
<input TYPE=&quot;image&quot; SRC=&quot;images/submit_button.gif&quot;
BORDER=&quot;0&quot; WIDTH=&quot;65&quot; HEIGHT=&quot;23&quot;>
</td>
</tr>
</table>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top