I am facing a very weird issue here. I am calling an action (which is a view) and there I have got two buttons. There are separate handles for these buttons in javascript which is placed in the same .cshtml file. The code as mentioned below:
#model fbpm.Models.UserDetail
#{
ViewBag.Title = "My View"; }
<style type="text/css">
#top
{
width:360px;
float: left;
height:100px;
border-left: 1px solid black;
border-bottom: 1px solid black;
}
#right
{
width:360px;
float: left;
height:100px;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 1px solid black;
} </style>
<div id="top" class="display-field">
Name : #Html.DisplayFor(model => model.UserName)
<br />
<br />
<input id="userid" type="hidden" value = #Html.DisplayFor(model => model.UserID)></input>
Address : #Html.DisplayFor(model => model.FullAddress) <br />
#Html.DisplayFor(model => model.State) <br />
#Html.DisplayFor(model => model.Country)
<br />
<br />
</div>
<div id="top" class="display-field">
PAN # : #Html.DisplayFor(model => model.PANNo)
<br /><br />
Booked Date : #Html.DisplayFor(model => model.BookedDate)
<br />
<br />
<br />
<br />
</div>
<div id="right" class="display-field">
Booked Amount : INR #Html.DisplayFor(model => model.BookedAmount)
<br /><br />
Remaining Amount : INR
<label id="ramt"/>
<br />
<br />
<br />
<br />
</div>
<div id="display" style="clear:both;">
<button type="button"style="width:150px" id="paysched" name="paysched" onclick="handleflat();">Payment Schedule</button>
<button type="button" style="width:150px" id="flat" name="flat" onclick="handleps();"> Flat </button>
</div>
<br />
<div id="container" style="clear:both;"> Click on the above button to display Flat/Payment Schedule </div> <script type="text/javascript" language="javascript">
$.get('#Url.Action("GetRamt", "Customer")?id=' + document.getElementById("userid").value,
function (amount) {
document.getElementById("ramt").innerHTML = amount;
});
function handleflat() {
$.get('#Url.Action("GetFlat", "Customer")?id=' + document.getElementById("userid").value,
function (viewResult) {
$("#container").html(viewResult);
});
}
function handleps() {
$.get('#Url.Action("paysched", "Customer")?id=' + document.getElementById("userid").value,
function (viewResult) {
$("#container").html(viewResult);
});
} </script>
However, When I click on the second button (Payment Schedule), its calling the Flat button action. And when i keep clicking the second button, sometimes it works! And when it works, I click on some other area in the window, the first button's function is called.
Please can someone help?
*EDIT: The first button is always highlighted and I guess, thats the problem why the first button's function is always called. I dont want this behavior *
EDIT2: Meanwhile, i was just playing around with the code and I changed the Button to Radio buttons! Initially, both the radio buttons were not selected and when I click on the second button, the second button is getting selected. Now, is the interesting part => When I click on any part of the result view, the first radio button is getting selected!!! And now, both the radio buttons are ON!!! :(
*EDIT3: And I named both the radio buttons with the same name. Now, clicking on any part of the result div is making the first radio button selected! *
Placing the mouse over the DIV - CONTAINER, highlights the First button and thats why that button is getting clicked.
Regards,
Hari
Apart from the fact that your html could use some cleaning up for example:
<input id="userid" type="hidden" value = #Html.DisplayFor(model => model.UserID)></input>
Becomes:
#Html.HiddenFor(model => model.UserID)
Also ... nbsp; among other things.
And the javascript could be something like this:
$(function () {
// get the user id
var userId = $('#UserID').val();
// get 'Remaining Amount' -> this should be included in your view model frankly speaking
// getting it like this is not "ideal"
$.get('#Url.Action("GetRamt", "Customer")?id = ' + userId, function (responseData) {
$('#ramt').text(responseData);
});
// bind the button events
$('#flat').click(function() {
var flatUrl = '#Url.Action("GetFlat", "Customer")?id = ' + userId;
getCustomerData(flatUrl);
});
$('#paysched').click(function () {
var paySchedUrl = '#Url.Action("paysched", "Customer")?id = ' + userId;
getCustomerData(paySchedUrl);
});
// handle the response from the server for the customer data
var getCustomerData = function(url) {
$.get(url, function(responseData) {
$('#container').html(responseData);
});
};
});
I hope this helps.
Related
My code are below
#using (Html.BeginForm("PostUsingParameters", "loopW"))
{
<input type="text" name="num" /><br />
<input type="submit" value="Click Me" />
}
after pressing the button it jumps to the destination page but there is no any CSS effect to the result.
I have tried many ways including using FormMethod.Post new { #class = "example" }. Unfortunately, it’s no use to make the CSS take effect in the destination page. Would appreciate some advice on this problem.
I use .Net 5.0 in my project. Moreover, I want the CSS working on new page after pressing submit button.
<head>
...
<style>
.example {
font-size: 70px;
color: red;
}
</style>
</head>
<body>
<div>
<section>
#using (Html.BeginForm("PostUsingParameters", "loopW", FormMethod.Post, new { #class = "example" }))
{
<input type="text" name="num" /><br />
<input type="submit" value="Click Me" />
}
</section>
</div>
</body>
I have an ASP.Net user control, it has a text box and list box, I have given them unique ids and classes, as a user control if I drag it twice or more on asp.net page, it will not work because of same ids when compiled, please see the code below -
$("#liAutoCompleteTextBox").html("<ul class='ecm-autocomp-light'>");
$("#ddlAutoCompleteTextBox > option").each(function () {
if($(this).text().toLowerCase().match(txtVal)) {
$("#liAutoCompleteTextBox").append("<li class='ecm-autocomp-light' onclick=updateToAutoCompleteTextBox('" + encodeURI(this.text) + "')><a onclick=updateToAutoCompleteTextBox('" +encodeURI( this.text) + "')>" + this.text + "</a></li>");
}
});
The user control has script like above, this is just one example.
And in aspx we have,
<label class="input" id="AutoCompleteTextBoxText" runat="server">
<asp:TextBox ID="txtAutoCompleteTextBox" AutoCompleteType="None" autocomplete="off" onfocusout="$('#liAutoCompleteTextBox').fadeOut()" onkeyup="liAutoCompleteTextBoxFunc()" runat="server" CssClass="input-sm isReq isRestrictedText txtAutoCompleteTextBoxCls"></asp:TextBox>
</label>
<label class="select" style="display: none">
<asp:DropDownList ID="ddlAutoCompleteTextBox" ClientIDMode="Static" runat="server" CssClass="input-sm ddlAutoCompleteTextBoxCls">
</asp:DropDownList>
<i></i>
</label>
<div id="liAutoCompleteTextBox" class="customAutoCompDiv" style="position: absolute; display: none; padding: 5px; border: 1px #808080 solid; background: #fff; z-index: 1000; width: 90.5%;">
</div>
I want to make all the ids completely dynamic. Is there any specific control id which I can use with all the names and classes, or is there any other way to handle this?
If you change the liAutoCompleteTextBox div to a Panel (which is a div in html) and put the script inside the UserControl then it will work. When it is a Panel you have access to it's ClientID. Now no matter how much controls you put on the parent page, the javascript will still reference the correct controls.
<!-- begin user control -->
<label class="input" id="AutoCompleteTextBoxText" runat="server">
<asp:TextBox ID="txtAutoCompleteTextBox" AutoCompleteType="None" autocomplete="off" onfocusout="$('#liAutoCompleteTextBox').fadeOut()" onkeyup="liAutoCompleteTextBoxFunc()" runat="server" CssClass="input-sm isReq isRestrictedText txtAutoCompleteTextBoxCls"></asp:TextBox>
</label>
<label class="select" style="display: none">
<asp:DropDownList ID="ddlAutoCompleteTextBox" ClientIDMode="Static" runat="server" CssClass="input-sm ddlAutoCompleteTextBoxCls">
</asp:DropDownList>
<i></i>
</label>
<asp:Panel ID="liAutoCompleteTextBox" runat="server" CssClass="customAutoCompDiv" Style="position: absolute; display: none; padding: 5px; border: 1px #808080 solid; background: #fff; z-index: 1000; width: 90.5%;"></asp:Panel>
<script type="text/javascript">
$("#<%= liAutoCompleteTextBox.ClientID %>").html("<ul class='ecm-autocomp-light'>");
$("#<%= AutoCompleteTextBoxText.ClientID %> > option").each(function () {
if ($(this).text().toLowerCase().match(txtVal)) {
$("#<%= liAutoCompleteTextBox.ClientID %>").append("<li class='ecm-autocomp-light' onclick=updateToAutoCompleteTextBox('" + encodeURI(this.text) + "')><a onclick=updateToAutoCompleteTextBox('" + encodeURI(this.text) + "')>" + this.text + "</a></li>");
}
});
</script>
<!-- end user control -->
What is important to remember that when the Control and the Control.ClientID are in the same Page/UserControl their ID will be correct.
I'm importing a mailing list into MailChimp and am having trouble with implementing interest groups correctly. Here's my situation: subscribers have opted in to receive updates for one or more geographic area (NYC, Boston, etc.) The vast majority of users belong to only one group, but it's important to allow people to sign up for more than one group. MailChimp groups work for this perfectly, EXCEPT for the fact that groups can't be made required fields...except using the advanced form design mode.
Per the Mailchimp documentation:
Group fields can not be set to required for a sign up form. The logic in our database is such >that Groups shouldn't be required because they are considered to be a list of options or >interests for segmenting and it is valid for someone to have no interests. If you are an >?>advanced user or have a developer that can help out, a required Groups field could be custom >coded using the Advanced forms option(available only to paid accounts) in your account.
I've done a ton of searches to find even the first steps to addressing this through the advanced form mode but have come up empty so far. I'm no expert on HTML/Javascript/PHP but I know enough to tinker and get things done through trial and error. Also, the form will ideally be hosted on a WordPress page.
I have experienced same problem with you.
What i did is added a javascript validation to the Mailchimp embed code.
This is the example of the code. I was using radio buttons.
I'll just remove the form action button for personal reasons
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; width:650px;margin:auto;}
.mc-field-group{width:50% !important;margin:auto;}
.mc-field-group.input-group{width:96% !important;margin:auto;}
#mc-embedded-subscribe{
margin: auto;
width: 150px !important;
height: 30px !important;
font-size: 15px !important;
background: #eb593c !important;
position: relative !important;
color: #fff !important;
margin-left: 38% !important;
}
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div class="indicates-required"><span class="asterisk">*</span> indicates required</div>
<div class="mc-field-group">
<label for="mce-EMAIL">Email Address <span class="asterisk">*</span>
</label>
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
<label for="mce-FNAME">First Name </label>
<input type="text" value="" name="FNAME" class="" id="mce-FNAME">
</div>
<div class="mc-field-group input-group">
<strong>How Often Would You Like to Hear From Us: <span class="asterisk">*</span></strong>
<ul><li><input type="radio" value="4" name="group[10709]" id="mce-group[10709]-10709-0"><label for="mce-group[10709]-10709-0">Somewhat Weekly: THRIVING IS THE NEW YOU Blog Posts sent via Email</label></li>
<li><input type="radio" value="8" name="group[10709]" id="mce-group[10709]-10709-1"><label for="mce-group[10709]-10709-1">Monthly Vibrancy Roundup: It's like a E-Newsletter but way groovier.</label></li>
</ul>
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_ef38bee7ba91bb0815db87917_22d8d62dc8" tabindex="-1" value=""></div>
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</form>
<script type="text/javascript">
var forms = document.getElementById('mc-embedded-subscribe-form');
try {
forms.addEventListener("submit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}, false);
} catch(e) {
forms.attachEvent("onsubmit", function(event)
{
var off_payment_method = document.getElementsByName('group[10709]'); //this is the name of the radio buttons
var email = document.getElementById('mce-EMAIL');//email field
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
event.preventDefault();
return false;
}
var ischecked_method = false;
for ( var i = 0; i < off_payment_method.length; i++) {
if(off_payment_method[i].checked) {
ischecked_method = true;
}
}
if(!ischecked_method){
alert("Please choose from How Often Would You Like to Hear From Us:");
event.preventDefault();
return false;
}else{
return true;
}
}); //Internet Explorer 8-
}
</script>
</div>
<!--End mc_embed_signup-->
Have you tried adding class="required" to each group field in the advanced editor? When I look at my required fields, they are declared with this class (except the email, which seems to have a special "email required" class:
<div class="mc-field-group"><label for="mce-FNAME">First Name <span class="asterisk">*</span>
</label>
<input class="required" id="mce-FNAME" type="text" name="FNAME" value="" /></div>
<div class="mc-field-group"><label for="mce-LNAME">Last Name </label>
<input id="mce-LNAME" type="text" name="LNAME" value="" /></div>
In this example, taken from one of my forms (hosted on a WP page), FNAME is required, but LNAME is not.
I have done one webcam project which will supports view live webcam images.I am using "ENTER USB 2.0" locally its working fine..when i upload it to the webserver and test with client browser..Its not working..its getting errors as "No devices Found"..is there any server settings to detect the webcams?..
How can we detect any type of webcams in asp.net..?Or is there any activeX plug-ins for detecting the webcam on client browsers..
Its very important to me..please share with me..if you have any ideas?
thanks in advance..
I used jpegcam once to upload photo from webcam. Hope this helps. Basic code is like (using jquery):
<script type="text/javascript" src="<path to webcam.js (inside jpegcam)>"></script>
<script type="text/javascript">
$(function () {
webcam.set_swf_url('path to webcam.swf(inside jpegcam)');
webcam.set_api_url(document.URL);
webcam.set_quality(90); // JPEG quality (1 - 100)
webcam.set_shutter_sound(false);
$("#imgWrapper").css({ height: "262px",
width: "215px",
border: "solid 1px #aaa"
});
var pb = $("#tp");
pb.addClass("spbtn");
pb.click(function () {
$("#fc").html(webcam.get_html(215, 262));
viewCam(true);
});
});
function viewCam(show) {
if (show) {
$("#sc").hide();
$("#iUploadFrame").fadeIn();
}
else {
$("#iUploadFrame").hide();
$("#sc").fadeIn();
}
}
function camReset() {
webcam.reset();
setCamInstruction("Adjust, snap, then upload", "#666");
}
function setCamInstruction(msg, c) {
$("#upStatus").html(msg).css("color", c);
}
function handleUpload() {
var gi = $("#ghimg");
gi.css("visibility", "visible")
webcam.upload(document.URL, function () {
gi.css("visibility", "hidden")
setCamInstruction("Upload complete!", "green");
});
}
</script>
html:
<div id="sc" style="width: 218px">
<div id="imgWrapper">
<img src="<path to a placeholder image>" alt="no photo" id="imgPhoto"
runat="server" height="262" width="215" />
</div>
<br />
<div style="text-align: center">
<span id="tp">Open Webcam</span>
</div>
<br />
</div>
<div id="iUploadFrame" style="display: none;">
<div id="fc">
-- Cam Content --
</div>
<div id="upStatus" style="padding: 5px 0; color: #666;">
Adjust, snap, then upload</div>
<input type="button" value="Snap" onclick="webcam.freeze()" />
<input type="button" value="Reset" onclick="camReset();" />
<input type="button" value="Upload" onclick="handleUpload()" />
<div class="progress_beside_inline" id="ghimg">
</div>
</div>
Im implementing a site with shopping cart features and want the user to be able to select the color for the product they are purchasing.
Let's say I started with something like this:
<form action="">
<input type="radio" name="color" value="red" />
<input type="radio" name="color" value="green" />
<input type="radio" name="color" value="black" />
</form>
What CSS is needed to show coloured boxes for each of the options, with the boxes displayed horizontally and have a border around the selected option?
Along the lines of:
[redbox] [greenbox] [blackbox]
You can check out jQuery UI's Button http://jqueryui.com/demos/button/#radio
It allows you to create nice styles for checkboxes/radio buttons and so on..
I'm not sure if you'd want to use a whole framework for that though, but as far as I know, radio buttons aren't very 'stylable'. You'd need to create another element next to it, and change the selected value of the radio button programatically.
Hope this helps,
Marko
Because each browser is going to render the button differently, I would use a series buttons that are altering the state of a hidden input field. (I didn't test this, but it's the general idea):
<form id="myForm" action="">
<input type="hidden" id="color" name="color" value="red" />
<button type="button" style="background-color:red; width:50px; height:50px;"></button>
<button type="button" style="background-color:green; width:50px; height:50px;"></button>
<button type="button" style="background-color:blue; width:50px; height:50px;"></button>
</form>
<script>
/* I like jQuery, sue me ;) */
$(function() {
$('#myForm button').click(function() {
$('#color').val($(this).css('background-color'));
$(this).siblings('button').css('border','none');
$(this).css('border','2px solid black');
});
});
</script>
I would think that you wouldn't use radio boxes. You can have a hidden input field that stores the color, and 3 div's for the color boxes. onclick events would handle setting the classes so the selected item has the border and the hidden value is set.
Using jQuery it would look something like this:
<style type=text/css>
.cchoice { width:10px; height:10px; }
.red { background-color: red; }
.green { background-color: green; }
.blue { background-color: blue; }
.cpicked { border:2px solid yellow; }
</style>
<input type="hidden" name="colorChoice" id="colorChoice" value="">
<div id="cc_Red" class="cchoice red" onclick="makeChoice('red');">
<div id="cc_Green" class="cchoice green" onclick="makeChoice('green');">
<div id="cc_Blue" class="cchoice blue" onclick="makeChoice('blue');">
<script type=text/javascript>
function makeChoice(col) {
if (col != 'green') $('#cc_Green').removeClass('cpicked');
if (col != 'blue') $('#cc_Blue').removeClass('cpicked');
if (col != 'red') $('#cc_Red').addClass('cpicked');
$('#colorChoice').val(col);
}
</script>
Even if I have some syntax wrong, maybe this will set you on the right path?.. let me know if I can be of more help.