image form submit IE - html

Hey guys I want a form to be submitted but it just won't work in IE. Altough in mozilla and other browsers it is working. The code:
<input type="image" name="zoeken" src="knop_go.jpg" value="zoek" alt="zoek" />
What's the solution for this problem ?

It does work — it just doesn't send the value, just the co-ordinates.
If you are testing to see if that button each clicked, look to see if an x or y co-ordinate is set (as well as testing for the value).

A possible workaround would be a regular button with a css style for the image:
<form action="blah.aspx" method="post">
<input type="submit" class="button" name="zoeken" value="zoek" />
</form>
And in css:
.button {
border: 0px;
background: url("./knop_go.jpg");
width: 100x;
height: 60px;
}

You could try this inside a form tag (in fact, this will work):
<button type="submit">
<img src="btnaceptar.jpg"/>
</button>

OK, update, it works IF I press the button, but if I press enter, it still doesn't work...
fixed it by checking if another field isset, now it works...
But I saw if you don't press the submit button, he doesn't send a value.

Related

Odd browser compatibility issue with IE/Firefox

I have a login script based on PHP and Javascript. I couldn't figure out for the longest time why it would work in chrome and safari but not in firefox or internet explorer. I finally figured out the issue is with the html, instead of having the regular submit button I have an image for submit. and simply changing type="image" to type="submit" resolves the issue. Does anyone know why this is and if there's a compatible way to write the following
This works:
<input name="doLogin" type="submit" style="margin-left:90px;" id="doLogin3" value="Login">
This does not:
<input name="doLogin" type="image" src="login-btn.png" style="margin-left:90px;" id="doLogin3" value="Login">
if you are not going to be using js to submit your form, then the input type for your submit button should be submit. but if you really must have an image in place of your button, just position the image with css by setting it as the background of your button. no need to change input type to image. hope that helps.

Set the href of the submit input type

Could I have something like <INPUT TYPE="SUBMIT" NAME=submit VALUE=Submit>, but instead of being a submit button, it could be an image? Is there something like href?
The simplest way is to use an image as a submit button employing the HTML form tag.
<input type="image" src="IMAGE.GIF" alt="Submit button">
However, you can also use Javascript for more robustness
<a href="javascript:document.your_form_name.submit()">
<img src="IMAGE.gif" alt="Submit this form" name="sub_but" />
</a>
HTML already got it:
<input type="image" src="myimage.png" />
Clicking it is exactly like clicking a submit button, instead of value you define src and the coordinates of the click are also sent to the server.
Official documentation.
Edit - while the form submission itself is the same, there is one difference between <input type="submit" /> and <input type="image" /> which is the value sent to the server for the clicked button. With ordinary submit button, the value of the button is sent alongside its name and can be then used to know if the form has been submitted, for example. In case of image input, each browser behaves differently, some send the value some send coordinates but you can't rely on this anymore. So, if you depend on the submitted button value in the server side code using image button is not good idea.
<input type="image" src="image.png" /> does exactly what you ask. You can't rely on the name attribute for it though (for example if your server-side code checks for it as a reference for the form being submitted), because the browser sends name.x and name.y for the coordinates clicked.
That aside, the image input type is essentially the same as a submit button for most purposes.
You can use image in place of showing default submit button.
form input[type=submit] {
background : url("submit.png") no-repeat center center;
width : 115px; /* As per requirement */
height :52px; /* As per requirement */
border : none;
color : transparent;
}
Please note that type="image" support is lacking in some browsers so above mentioned styling is a safe way.
You can do like this, in 'scr' you can put your image link; it would be like image button.
<input type="image" src="images/submit.jpg" value="Submit" alt="Submit">

Form only submits when there is one input

I have a <form> element surrounding several inputs:
<form>
<div class="tr" id="widget306">
<div class="td col-grab">
<button type="button" class="button grab formwidget" id="widget611">m</button>
</div>
<div class="td col-name">
<input type="text" name="name" value="target volume profile 1" id="widget607" class="formwidget textbox">
</div>
<!-- ... etc ... -->
</div>
</form>
I would like to trigger a submit event on the form when the user presses enter while focused on an element (standard behavior for input elements wrapped in a <form> tag), but when I press enter, nothing happens (fiddle). If I remove all but one input element, the code works, and I get the expected behavior of pressing enter and triggering a form submit (fiddle).
How do I get the desired behavior (pressing enter submits the form) in the first example where I have multiple forms?
Note: I have found this same behavior in Safari 5.1, Chrome 17, Firefox 9, and IE 9.
Clarification: I know I can just throw some Javascript at it, but I'd like solve it with just markup.
Update: as some of you have helpfully pointed out, I can get the desired behavior by adding an <input type=submit>. The problem is I don't want the user to see the submit button. I can't just set its display to none, because then browsers won't submit when return is pressed, so I borrowed from QUnit and set the following:
HTML:
<input type=submit class=hide-me />
CSS:
.hide-me {
position: absolute;
left: -10000px;
top: -10000px;
}
I have noticed that forms don't like to submit without a submit button. The problem is simply resolved by adding a submit button. See this fiddle for a demonstration. Furthermore, browsers submit when a user presses enter by default, so fix that and you won't need a javascript trigger to cause it.
EDIT:
If you don't want to use a <input type="submit"> simply because it's styling deficiencies, consider a <button type="submit">, it should also do the trick. If you just don't want a submit button at all, stick with the CSS hack.
After trying it myself I couldn't believe it either.
Looks like this is the issue:
Why does forms with single input field submit upon pressing enter key in input
It's default behaviour for browsers to automatically submit simple forms (like search ones) which is why it's working when there is only one input. I believe if you want this functionality on complex forms you will need to use javascript. If you're not against using jQuery the following should do the trick.
$(function(){
$("#formid input").keypress(function(event){
if (event.which = 13){
$("#formid").submit();
}
}
}
Add an element
<input type="submit" name="xx" value="submit" />
it will trigger submit behavior automatically.
you can also use jQuery to handle press event.
Sean.
Try this one. i use this on my textarea with tinymce for a chat system
<script>
function getKeystroke(e)
{
var keynum;
keynum = (window.event) ? event.keyCode : e.keyCode;
switch(keynum)
{
case 13: /* enter key */
document.getElementById("s_say").click();
document.getElementById("s_message").focus();
break;
}
}
</script>
s_say is the ID of the input type submit btn.

Input Type image submit form value?

I am using this code to try and submit a value via form but it doesn't seem to submit anything...
I would normally use a checkbox or Radio buttons for multiple options but I want to use an image to do this.
Is this code wrong?
<input id="test1" name="test1" type="image" src="images/f.jpg" value="myValue" alt="" />
So I want to pass the value in value="myValue".
The form works fine so that's not the problem, I just need help with the input part not submitting as I know that works.
Thanks
An input type="image" only defines that image as the submit button and not as an input that can carry over a value to the server.
Using the type="image" is problematic because the ability to pass a value is disabled. Although it's not as customizable and thus as pretty, you can still use your images ao long as they are part of a type="button".
<button type="submit" name="someName" value="someValue"><img src="someImage.png" alt="SomeAlternateText"></button>
I was in the same place as you, finally I found a neat answer :
<form action="xx/xx" method="POST">
<input type="hidden" name="what you want" value="what you want">
<input type="image" src="xx.xx">
</form>
I've found that image-buttons DO return a response, but you should NOT use a value-option. What I see returned are two version of the name="MYNAME" with .X and .Y endings.
For example:
<input type="image" src="/path-to/stop.png" name="STOP" width="25" height="25" align="top" alt="Stop sign">
This is within your <form> to </form>. If you click the image, what's returned are STOP.X and STOP.Y with numeric values. The existence of either indicates the STOP image-button was clicked. You don't need any special code. Just treat it as another kind of "submit" button that returns a pair of augmented NAMEs.
I've tried this on Safari, Firefox and Chrome. The image wasn't displayed with Safari, but where it was supposed to be located, my cursor turned into a finger-icon, and I could click it.
Some browsers (IIRC it is just some versions of Internet Explorer) only send the co-ordinates of the image map (in name.x and name.y) and ignore the value. This is a bug.
The workarounds are to either:
Have only one submit button and use a hidden input to sent the value
Use regular submit buttons instead of image maps
Use unique names instead of values and check for the presence of name.x / name.y
Here is what I was trying to do and how I did it. I think you wanted to do something similar.
I had a table with several rows and on each row I had an input with type image. I wanted to pass an id when the user clicked that image button. As you noticed the value in the tag is ignored. Instead I added a hidden input at the top of my table and using javascript I put the correct id there before I post the form.
<input type="image" onclick="$('#hiddenInput').val(rowId) src="...">
This way the correct id will be submitted with your form.
Inputs of type="image" don't send their name/value pair when used to submit the form. To me, that sounds like a bug, but that's how it is.
To get around this, you can replace the input with a button of type="submit", and put a img element inside.
Unfortunately, that causes your image to be in a ugly HTML "button". However, assuming you aren't using the standard HTML button anywhere, you can just override the stylesheet, and then everything should work as expected:
button, input[type="submit"], input[type="reset"] {
background: none;
color: inherit;
border: none;
padding: 0;
font: inherit;
cursor: pointer;
outline: inherit;
}
<form action="/post">
<input name="test">
<button type="submit" name="submit_button" value="submitted">
<img src="https://via.placeholder.com/32" alt="image">
</button>
</form>
You could use a radio button/checkbox and set it to hide the button in css and then give it a label with an image.
input[type="radio"] {display: none}
input[type="radio"] + label span {display: block}
Then on the page:
<input type="radio" name="emotion" id="mysubmitradio" />
<label for="mysubmitradio"><img src="images/f.jpg" />
<span>if you need it</span></label>
And then set it to submit using javascript:
document.forms["myform"].submit();
Solution:
<form name="frmSeguimiento" id="frmSeguimiento" method="post" action="proc_seguimiento.php">
<input type="hidden" name="accion" id="accion"/>
<input name="save" type="image" src="imagenes/save.png" alt="Save" onmouseover="this.src='imagenes/save_over.png';" onmouseout="this.src='imagenes/save.png';" value="Save" onclick="validaFrmSeguimiento(this.value);"/>
function validaFrmSeguimiento(accion)
{
document.frmSeguimiento.accion.value=accion;
}
Regards,
jp
well if i was in your place i would do this.I would have an hidden field and based on the input image field i would change the hidden field value(jQuery), and then finally submit the hidden field whose value reflects the image field.
You could use formaction attribute (for type=submit/image, overriding form's action) and pass the non-sensitive value through URL (GET-request).
The posted question is not a problem on older browsers (for example on Chrome 49+).
Add this
name="myvalue"
To your tag.
To submit a form you could use:
<input type="submit">
or
<input type="button"> + Javascript
I never heard of such a crazy guy to try to send a form using a image or a checkbox as you want :))

Firefox 4 submit button problem

In Firefox 4 when I press submit button nothing happens. The code of button is:
<input class="button" type="SUBMIT" value="Login" form="dataForm" name="event_Login">
On Firefox 3.6 the button is working OK. Some solution?
It appears the problem is with form="dataForm". When I remove that attribute, the button works fine again in FF4. The value of the form attribute should be the id of a form to submit, otherwise the button will do nothing (at least in FF4). For instance, this button will work:
<form id="dataForm">
<input ... form="dataForm" />
</form>
Not sure if it's your problem, but I had a similar one - solution was putting "SUBMIT" in lowercase.