Image/Icon as submit button - html

How to make icon/image to be used as submit button (input)? I mean I have tried input type "image" but then I had white background around the envelope that I want to be my submit button. I would prefer to use '✉' code but I can't get rid off the background around it.
I am using code like this now but it really isn't really what I want
<input name="send" value="✉" type="submit">
that is how it look right now

You can use <input type="image"> , more info at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image

You could use the with a a class to apply the background image
<button class="mybgImage"></button>
With the CSS..
.mybgImage {
width: 40px;
height: 30px;
background-image {'theNameOfMyBackgroundImage.png'}
}

Related

Can characters inside a submit button be formatted differently?

I have a form and the form has a submit button with html code like this:
<input type='Submit' name='sel' value='Submit Here'>
I want the word "Submit" to have font-size of 10px and black color while the word "Here" to have font-size of 12px and red color. Is it doable without using back-ground image?
No, you can't do that. Whatever style you add to the input element will be applied to the whole text, you won't be able to select individual characters. However, you can use a different element that supports content, such as a button, where you can add the content you want and style it...
<button type="submit">
<span class="black">Submit</span> <span class="red">Here</span>
</button>
And then apply the styles...
span.black {font-size:10px;color:black}
span.red{font-size:12px;color:Red}
An example below...
JS Fiddle Example

How to add a background just to a buttons value?

So basically, I have a form submit button:
<input type="submit" id="submit" name="submit" value="Click to Search">
I would like to ONLY style the value, 'Click to Search'.
Currently, the button has a background color, although I would like to assign an individual background to just the value.
Is this possible without changing the structure of my HTML?
If that's always the value, how about using Attribute Selectors?
input[type=submit][value='Click to Search'] {
background-color: red;
}
That will style only <input>s whose type attribute's value is submit and value is Click to Search. See a demo here.

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">

How to hide text field in Html File Upload

I am wondering how to hide the text field portion of a standard html file upload tag
for example
<input type="file" name="somename" size="chars">
This generates obviously a text field and next to that field is a browse button... I want to hide the text field part but keep the button.
This will surely work i have used it in my projects.I hope this helps :)
<input type="file" id="selectedFile" style="display: none;" />
<input type="button" value="Browse..." onclick="document.getElementById('selectedFile').click();" />
I'd recommend hiding the whole thing and putting a separate button object which, when clicked, will end up clicking the input's browse button.
You can do this with CSS and javascript -- check out this article (actually the second time I've used this reference today).
The easiest way as not mentioned in any answer would be to use a label for the input.
<input type="file" name="myFile" id="myFile">
<label for="myFile">Choose your file</label>
input[type="file"] { display: none; }
Using label will be useful because clicking on the label is clicking on the input.
This will only work when input's id is equal to label's for attribute.
You can put an image as a background for the button.
That worked for me, a while ago.
The file input button is extremely difficult to style and manipulate, mainly for security reasons.
If you really need to customize your upload button, I recommend a Flash based uploader like SWFUpload or Uploadify that enables you to use a custom image as button, display a progress bar, and other things.
However, its basic philosophy differs from just embedding a control into a form. The uploading process takes place separately. Make sure you check out first whether this works for you.
DEMO
Pure css and html
The trick is to use a button above the input file button.
Plus, you should set
filter: alpha(opacity=0);
to the input file.
You could possibly hide the whole element and show a button or link instead. This is rather easy.
<input type="file" name="file" id="fileupload" style="width:200px; display:none;" onchange="submitmyform();" />
<input type="button" value="Select an Image" onclick="$('#fileupload').click();" />
The file upload element is hidden. The button will fire the click event and shows the file browser window. On selecting a file, the change event is fired and this can submit a form or call a script function, whatsoever.
Hope this helps...
input[type="file"] { outline: none; cursor: pointer; position: absolute; top:0; clip: rect(0 265px 22px 155px); } /* Hide input field */
#-moz-document url-prefix()
{
input[type="file"] { clip: rect(0, 265px, 22px, 125px); } /* Mozilla */
}
* > /**/ input[type="file"], x:-webkit-any-link { clip: rect(0, 86px, 22px, 0); } /* Webkit */
This will do the same without JavaScript, but requires absolute positioning to use the clip property.
References
Custom Upload Button
CSS Wikibook: Clipping
If you are using jQuery, have a look at this plugin - https://github.com/ajaxray/bootstrap-file-field
It will display the file input field as a bootstrap button and will show selected file names beautifully. Additionally, you can set various restrictions using simple data-attributes or settings in js.
e,g, data-file-types="image/jpeg,image/png" will restrict selecting file types except jpg and png images.
Try adding this css to your input
font-size: 0;
Hello I get inspired by #shiba and here is solution in Angular 9:
<input type="file" [id]="inputId" class="form-control" [style.display]="'none'"
[accept]="acceptedDocumentTypes" [multiple]="true" #fileInput
(change)="fileChange($event)" (blur)="onTouched()">
<input type="button" class="form-control" value="Browse..." (click)="fileInput.click()"/>
you can set it's content to empty string
like this :
<input type="file" name="somename" size="chars" class="mycustominput">
and in your css file :
.mycustominput:after{
content:""!important;
}
You can hide the text behind the button changing the buttons width to 100% using the webkit-class. The button will then overlap the <span> behind itself on the shadow-root.
There is no need to apply any opacity, transparency or hidden attribute to the button, it's just a bit different to style compared to other objects and this will keep the localisation of the form element alive.
This will do the trick and is supported (MDN):
input[type=file]::-ms-browse { /* legacy edge */
width: 100%;
}
input[type=file]::file-selector-button { /* standard */
width: 100%;
}
input[type=file]::-webkit-file-upload-button { /* webkit */
width: 100%;
}

How to remove 'submit query' from a form submit?

I have an html form and the submit button says "submit query". How can I remove this text? I am using a background image for the submit button and this text is messing up the button :( Any help would be greatly appreciated.
If you do not give your submit button a value
<input type="submit" />
instead of something like
<input type="submit" value="Submit" />
it will display 'submit query' by default. Try giving it a space as the value.
use:
<input type='submit' name='btnTest2' value=''>
Leave the value blank and there will be no words on the button. Since you're using a background image a for the button, give the button a height and width, otherwise it will display as a small gray blip (because there are no words on the button).
Background images are not content. If you want to use an image to tell people what a submit button will do, use a real image. As a bonus that allows you to provide alternative text for users who cannot see the image (e.g. because it failed to load or because they are blind).
<button type="submit">
<img src="example.png" alt="Submit">
</button>
Just use the value attribute as shown below:
<input value="Whateveryouwant" type="submit">
You just have to give it a value:
<input type='submit' name='btnTest'>
<input type='submit' name='btnTest2' value='Push Me'>
In the example above, btnTest renders as "Submit Query" while btnTest2 renders as "Push Me". Hope this helps.
UPDATE: You can do this to not display any text.
<input type='submit' name='btnTest2' value='' style="width:100px;">
Not sure if this was relevant then, but we would use type="image" rather than type="submit"
Just put a space between the value quotes. Simple fix.
Read the question before you reply. You may actually help someone.
Unfortunately, this does not work, at least not in a CMS. I've tried the space and the but IE8 will not recognize it. If I put the same in the value, it reverts back to 'Submit Query'. Just updating for anyone else who finds this method through a search.
EDIT : I added text indent: -9999px; to my CSS, and it seems that it worked. I still added the space in the value attribute for good measure.
I had this issue as well. If you don't set a value for a submit button it defaults to "Submit Query". I assume you are using an image for your submit button since you have the default value.
If you want to fix it for IE8 add a text indent using CSS which will push the default value off the screen.
text-indent:9999px;
If you want to fix it for IE9 you also need to change the default value because the text-indent doesn't work :( in your submit button add the following:
value=" "
I found this to work without a non-breaking space and tested it to my satisfaction on the IE's on browserstack. If you want to use the breaking space, feel free; I'll include the code.
value=" "
Also, thank you to the other stack-responders, you helped me fix this issue on IE9.
Also you inspired me to post my findings here and possibly help others!
If you are using something like a jQueryUI dialog button then you do not want to have the input button show up in the form, but rather just have it in the footer of the dialog. I accomplished this by doing the following:
Because IE will automatically put in an <input type="submit" /> I put this in the form instead: <input type="submit" style="display:none" />
Then later in the dialog JavaScript I put:
$("#register-dialog").dialog({
title: "Register",
modal: true,
width: 700,
buttons: {
Register: function () {
$('#registrationForm').submit();
},
Close: function () {
$(this).dialog("close");
}
}
});
Just remove the text with jQuery?
jQuery:
$('#btnSubmit').val('');
Plus the solutions mentioned with HTML and jQuery, you can put
font-size: 0px;
for the input and it wouldn't show the text anymore.
This worked in my case.
that's it browser show default use this
value="submit" is important
use attribute value="submit"
nothing just do this
<input type="submit /"
a slash with a space and u will not see the Submit or Submit Query no need to give value