I have this on my cshtml:
<button onclick="save()" id="fundersSave" data-action="save-funder" type="button" class="btn btn-primary btn-lg">#Strings.Buttons_Save</button>
Then on my cshtml I have added the javascript:
<body>
<script type="text/javascript">
function save(){
var $form = $('.fancybox-inner').find('[data-area="funder-detail"]');
$form.on('click', '[data-action="save-funder"]', function () {
alert();
var selected1 = $form.find('input[type="radio"]:checked').val();
if ($('input[type="radio"]:checked').length == 0) {
parent.$.fancybox.close();
}
else {
document.getElementById("txtFunder").value = selected1;
parent.$.fancybox.close();
}
});
}
</script>
</body>
When I click on the [Save] button, I get undefined error.
If you included your jquery librairy at the bottom of your _layout, move it just after the body tag !
Related
I wanted to clear the value of text inside the input on the click of a button:-
Here is my code:
'''
<head>
<script>
function myfunction1() { //remember code var
texttosave = document.getElementById('textline').value;
localStorage.setItem('mynumber', texttosave);
document.getElementById('remember').value = ''
}
function myfunction2() { //recall code
document.getElementById('recalledtext').innerHTML =
localStorage.getItem('mynumber');
}
</script>
</head>
<body>
<input type="text" id="textline" />
<button id="remember" onclick='myfunction1()'>remember text</button>
<button id="recaller" onclick='myfunction2()'>recall text </button>
<p id="recalledtext">Loading</p>
</body>
</html>'''
I have did the correct thing, I think but please help as it is not working.
You need to put the value into a variable:
function myfunction2() { //recall code
// ...
var my_number = localStorage.getItem('mynumber');
}
Looks like the problem is that you dont do anything with the data you read from local storage.
A quick fix below.
function myfunction2() { //recall code
document.getElementById('recalledtext').innerHTML =
document.getElementById('remember').value = localStorage.getItem('mynumber')
}
I'm trying to pass a button value on a form submit in conjunction with a jquery confirm dialogue, but it's not going through. I understand it has something to do with the script using a "form.submit" function but I'm not familiar enough with JS to code a workaround to the problem.
Is there a way to maybe reassign the first button's value to a new JS variable and pass that instead?
I've simplified the form down to its basic elements to make it easy to follow. The data I'm trying to pass in this example is "123" using the button tied to the confirm dialogue script. A second "regular button" is added to demonstrate a successful form submission. Some PHP gathers in the POST data and displays it.
// Results:
// $regularbutton = '456';
// $alertbutton = '';
testpage.php:
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript">
//<![CDATA[
$(function () {
'use strict';
function confirmDialog(title, message, success) {
var confirmdialog = $('<div></div>').appendTo('body')
.html('<div><h6>' + message + '</h6></div>')
.dialog({
modal: true,
title: title,
zIndex: 10000,
autoOpen: false,
width: 'auto',
resizable: false,
buttons: {
Yes: function () {
success();
$(this).dialog("close");
},
No: function () {
$(this).dialog("close");
}
},
close: function() {
$(this).remove();
}
});
return confirmdialog.dialog("open");
}
$('#submit_alert').on('click', function (e) {
e.preventDefault();
var form = document.getElementById('form_alert');
confirmDialog('Confirm', 'Are you sure you want to proceed?', function () {
form.submit();
});
});
});
//]]>
</script>
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
</head>
<body>
<?php
extract($_POST);
echo "button1: $alertbutton <br>";
echo "button2: $regularbutton <br>";
?>
<form method="post" id="form_alert" action="testpage.php">
<button name="alertbutton" value="123" id="submit_alert">Alert Button</button>
<button name="regularbutton" value="456">Regular Button</button>
</form>
</body>
</html>
The value of the button is not commited.
You could inject a hidden field before calling the form.submit():
confirmDialog('Confirm', 'Are you sure you want to proceed?', function () {
$('#form_alert').append('<input type="hidden" name="alertbutton" id="submit_alert_hidden" value="' + $('#submit_alert').val() + '" />');
form.submit();
});
You can use the attribute data-* to pass some datas :
$(function()
{
$(".MyButton").on('click', function(e)
{
// note that some-value is camelCased to someValue
console.log(e.target.dataset.someValue);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="MyButton" name="alertbutton" data-some-value="123" id="submit_alert">Alert Button</button>
<button class="MyButton" name="regularbutton" data-some-value="456">Regular Button</button>
I am using Twitter Bootstrap 2 and jQuery. I have simple HTML button as follows:
<button type="button" onclick="Redirect(1,'');" class="btn btn-danger">Cancel</button>
In the head section I have a javascript function as follows:
function Redirect(id, push) {
if (id == 1) {
if (push == 1) {
window.location.href('../dashjs/dashboardjs.aspx?pushchart=1');
}
else {
window.location.href('../dashjs/dashboardjs.aspx');
}
return false;
}
}
For some reason, the function Redicect is never called in CHROME. This seems to be working in IE.
Any ideas of what might be the issue here.
The following are loaded in the head section:
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="../Content/bootstrap-button.js"></script>
any help will be much appreciated.
window.location.href actually isn't a method.
Try:
window.location.href = '../dashjs/dashboardjs.aspx?pushchart=1';
http://www.w3schools.com/jsref/prop_loc_href.asp
<script type="text/javascript">
function Redirect(id, push) {
if (id == 1) {
window.location.href = 'http://www.google.com';
} else {
window.location.href = 'http://www.yahoo.com.com';
}
return false;
}
</script>
</head>
<body>
<button type="button" onclick= Redirect(1,''); class="btn btn-danger">Cancel</button>
</body>
Try that. you need to assign location using =
If you want to use your syntax try window.location.replace as a redirect
Following is the script
<script type="text/javascript">
function DoFullScreen() {
var isInFullScreen = (document.fullScreenElement && document.fullScreenElement !== null) || // alternative standard method
(document.mozFullScreen || document.webkitIsFullScreen);
var docElm = document.documentElement;
if (!isInFullScreen) {
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
//alert("Mozilla entering fullscreen!");
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
alert("Webkit entering fullscreen!");
}
}
}
</script>
HTML
<body onload="DoFullScreen()">
<form id="form1" runat="server" >
<div id="div1">
<input id="bt1" type="button" value="button" />
Hello
</div>
</form>
</body>
I have tried
$(window).load
$(document).ready(function(){ $("#bt1").load
-- it's not possible force a fullscreen if it's not triggered by a user action
-- look at this
full-screen browser window on load document
on ready call your function
$(document).ready(function(){
DoFullScreen();
}
You can do it using pure javascript only like this:
<script type="text/javascript">
window.onload = function () {
// YOUR CODE STUFF
}
</script>
Lets say I have a string like this
var methodString = "<script>
var a;
var b;
function func1(v1, v2)
{
..///DO random stuff
}
</script>";
I then attach this code to the end of the body after a button click somewhere on the page
$(body).append(methodString);
How do I call this new function that i just appended
$("button1").click(function() { func1(a,b); }); //This doesn't seem to recognize the new method.
simple HTML
<button onclick="func1(a,b);">Click me</button>
With jQuery
<script type="text/javascript">
$('#myButton').click(function(){
func1(a,b);
});
</script>
<button id="myButton">Click me</button>