I'm writing an ASP-MVC application in C#. I have an input element of type submit and I want it to display an image. Here is the declaration of my button:
<input type="submit" value="Login" />
How can I display an image on that button?
Something like this should work:
<input type="image" src="/images/mypic.gif" />
Not sure I understand your question.
Related
I`ve got three radio buttons in my form. Every rbutton has own label as below
<form method="post">
<input type="radio" name="radio" "onclick="removeField()">
<label>Text1</label>
<br>
<input type="radio" name="radio" onclick="removeField()">
<label>Text2</label>
<br />
<input type="radio" name="radio" onclick="addField()">
<b>Another</b>
<br />
How I can get in my c# code label of radiobutton which is on?
You could just make the radio button's value be the same text as the label. When you post the form it should give you a key/value pair of 'radio=Text1' (or whatever.
<form method="post">
<input type="radio" name="radio" value="Text1" "onclick="removeField()">
<label>Text1</label>
<br>
<input type="radio" name="radio" value="Text2" onclick="removeField()">
<label>Text2</label>
<br />
<input type="radio" name="radio" value="Another" onclick="addField()">
<b>Another</b>
...
A few additional notes:
If label wraps the radio button, it becomes clickable and will toggle the radio button. Make sure to put the 'onclick' on the label tag if you do that.
The name 'radio' for a form field is not illegal, but I would suggest it's complicated. That radio button represents a property of your viewmodel (or of something) so I would suggest calling it something like 'SelectedText' or whatever.
I am trying to create a "next" button and a "back" button in my form. I want the "next" button to validate and submit the form. And I want the "back" button to simply go back to the "cart" page. But the "back" button keeps validating and trying to submit the form.
Here is my code:
<div class="buttons">
<button class = "button" id = "back">Back</button>
<input type="submit" value="Next" class="button" />
</div>
The reason I need the back link to be a button is so that it will look the same as the "next" button. Any ideas how I can get this working correctly?
A <button> element always submits the form. The same goes for a <input type="submit" /> element.
But a <input type="button" /> will not submit the form. That's what you want.
<div class="buttons">
<input type="button" class="button" id="back" onclick="window.location = '#Url.Action("Index", "Cart")';">Back</a>
<input type="submit" value="Next" class="button" />
</div>
Edit I'm not sure if you can put that inside an <a> element though. I reworked my example to use click events rather than a link. If it is valid to put inside a <a> element (can anyone confirm?), you can do it like that as well.
How can I print a View without showing the buttons on the printed paper?
Edit:
Currently my button simply does this:
<input type="submit" value="Drucken" onclick=" window.print(); " />
<input type="submit" value="Schließen" onclick=" window.close(); " />
Use a css file for printing, and hide the buttons (display:none) in that css file.
I have a simple form in my MVC3 site that allows users to create a contest entry. This has been implemented and works fine currently, but a request has been made to now allow users to make their entries private.
In my Entry model I added a boolean isPrivate. Then I figured I would change the HTML forms for create and edit to include a checkbox to specify whether the entry should be private.
I'm new to MVC3, but I figured I could simply change the action that the form posts to by including a new boolean parameter.
This unfortunately doesn't seem to work. Can anyone tell me how checkbox values are passed from an HTML form to a post action? This is probably fairly common, but I can't seem to find an example for this on the web. Almost all the examples out there simple show text inputs, I can't find anything with checkboxes.
Form:
<form method="post" action="../Entry/Create" enctype="multipart/form-data" onsubmit="return isValidInput()">
<input type="text" id="EntryTitle" name="EntryTitle" />
<div id="invalidTitle" class="invalidData"></div>
<p id="char-remaining">(100 characters remaining)</p>
<input type="text" id="EntryVideo" name="EntryVideo" />
<div id="invalidVideo" class="invalidData"></div>
<p id="vid-desc">(URL of the Video to Embed)</p>
<input type="file" id="ImageFile" name="ImageFile" />
<div id="invalidImage" class="invalidData"></div>
<p id="file-desc">(200x200px, jpeg, png, or gif)</p>
<textarea id="EntryDesc" name="EntryDesc"></textarea>
<div id="invalidDesc" class="invalidData"></div>
<br />
<input type="checkbox" id="isPrivate" name="isPrivate" />
Make my entry private.
<br />
(private entries will only be viewable by you and site administrators)
<br />
<button id="new-entry-save">save</button>
</form>
Action:
public ActionResult Create(string EntryTitle, string EntryVideo, HttpPostedFileBase ImageFile, string EntryDesc, Boolean isPrivate)
{
...
}
add value="true" to checkbox, also add hidden input after it with same name and value=false, i.e.:
<input type="checkbox" id="isPrivate" name="isPrivate" value="true" />
<input type="hidden" name="isPrivate" value="false" />
If you don't want to use hidden, use bool? instead of bool (e.g. nullable)
The other option is to have hidden text field with the same name to force data in unchecked field to be part of the post. See Post the checkboxes that are unchecked.
<form>
<input type='hidden' value='0' name='selfdestruct'>
<input type='checkbox' value='1' name='selfdestruct'>
</form>
I have a web app that has 3 buttons on it, under it there is a textbox with no text on it, I would like to create an event that fills the textbox when a user hovers his mouse over the button, can someone please point me in the right direction
Thank
<input type="button" onmouseover="javascript:document.getElementById('textbox').value='Hello'" />
<input type="text" id="textbox" name="textbox" />
You could simply use jQuery to do this
<input type="button" onmouseover="fillText()" />
<input type="text" id="textbox" name="textbox" />
And the JavaScript/jQuery
function fillText() {
$("#textBox").val = "Your Text";
}
server have no more info about client side, but you could do that with AJAX updatepanel. use a java function to write mouse position in hidden text. then read hidden text in server side with triggers (in condition update mode) or timer (in always update mode).