Pass Javascript Alert a Value - variables

I'm looking for a simple javascscript alert box. I need to be able to pass the alert box a string of text.
Is something like this possible? My syntax is probably wrong.
<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert(my_string_here);
}
</script>
</head>
<body>
<input type="button" onclick="show_alert()" value="Show alert box" string="alert for system number 2" />
</body>
</html>

<html>
<head>
<script type="text/javascript">
function show_alert(my_string)
{
alert(my_string);
}
</script>
</head>
<body>
<input type="button" onclick="show_alert('This will alert!')" value="Show alert box" string="alert for system number 2" />
</body>
</html>
This makes no sense thou. Better solution:
<html>
<head>
</head>
<body>
<input type="button" onclick="alert('Doh!')" value="Show alert box" string="alert for system number 2" />
</body>
</html>

Try:
<input type="button" onclick="alert('alert for system number 2');" value="Show alert box" />

What are you trying to do? alert('Your string here') should do the trick if you really need an alert.

Yes you can
function testAlert(val){alert(val);}

Yes this is possible
<script type="text/javascript">
function testAlert(val){alert(val);}
</script>
<input type=text onclick='testAlert(this.string)' string="something" value="clik here">

alert("alert for system number 2");

Related

Possibility of Taking Input from Keyboard or Dropdown menu

This is the chunk of my code
<div class="form-control">
<div class="input-group">
<span class="input-group-addon">
<input type="text" id = "fromuser"></input>
<select id="combobox">
<option value="">Select one...</option>
<option value="abc">abc</option>
<option value="cde">cde</option>
<option value="xyz">xyz</option>
</select>
</span>
<button type="submit">Submit</button>
</div>
</div>
What I am trying to achieve is that the User can either Type the value or select from the dropdown list. The challenge here is that the Input from Keyboard will be different from that given in dropdown. For example, the dropdown has three character string options but the user can type a number such as 10, 20, 30 etc.
Is this type of input allowed possible? If so, can someone help me.
The Closest I could come to my problem is by dropping the select and use autocomplete . The full test code is as follows:-
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
var availableTags = [
"abc",
"def",
"xyz"
];
$( "#tags" ).autocomplete({
source: availableTags
});
} );
function myFunction(){
var NameValue = document.forms["FormName"]["tags"].value;
window.alert(NameValue);
}
</script>
</head>
<body>
<form name="FormName" method="post" />
<div class="ui-widget" >
<input name= "tags" id="tags" type="text" onchange="myFunction()"/>
<button name="btn-signup" type="submit" value="Submit">Submit</button>
</div>
</form>
</body>
</html>
I know this is the final solution but maybe a way ahead.

MaterializeCSS noUiSlider range not working

I'm trying to create a MaterialiseCSS range slider which is based on noUiSilder. The documentation says:
Add a range slider for values with a wide range. This one is set to be a number between 0 and 100. We have two different types of sliders. nouiSlider is a 3rd party plugin which we've modified. To use the noUiSlider, you will have to manually link the nouislider.css and nouislider.js files located in the extras folder.
I did everyting unfortunately it is showing the defaut HTML range (like the one in the link).
My html:
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<link href="extras/noUiSlider/nouislider.css" rel="stylesheet">
<link href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="Stylesheet"></link>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript" src="extras/noUiSlider/nouislider.min.js"></script>
<script type="text/javasript" src="js/phonefinder.js"></script>
</head>
<body class="grey lighten-4">
<form>
<div class="input-field">
<p class="range-field">
<input type="range" id="test5" min="0" max="100" />
</p>
</div>
</form>
</body>
</html>
js/phonefinder.js:
$(function(){
var slider = document.getElementById('test5');
noUiSlider.create(slider, {
start: [20, 80],
connect: true,
step: 1,
range: {
'min': 0,
'max': 100
},
format: wNumb({
decimals: 0
})
});
});
What am I doing wrong?
The noUiSlider range isn't a a input type, it should be a div.
So:
<form>
<div class="input-field">
<p class="range-field">
<input type="range" id="test5" min="0" max="100" />
</p>
</div>
</form>
should be:
<form>
<div id="connect"></div>
</form>

sessionStorage from input

Can someone please tell what's wrong with this code?
Even when I change sessionStorage.setItem("item1"; document.test.value); to a fixed value like sessionStorage.setItem("item1"; "test"); it does nothing.
Is it a problem in the code or some browser setting?
The browser gives undefined for sessionstorage.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">`
function Session()
{sessionStorage.setItem("item1"; document.test.value);}
function Show()
{alert("Value 1 is " + sessionStorage.getItem("item1"));
}
</script>
</head>
<body>
<input type="text" id="test">
<button type="button" onclick="Session()">invoer</input>
<button type="button" onclick="Show()">show</input>
</body>
</html>
You have a semicolon where it should be a comma on this line:
{sessionStorage.setItem("item1"; document.test.value);}
Should be:
{sessionStorage.setItem("item1", document.test.value);}

How to create asp:table when click on add button

How to genera dynamic table it constant asp:textbox and sum other controls, when click on button in javascript.
Try This Code:
<html>
<head>
<script>
function changeLink()
{
document.getElementById('myAnchor').innerHTML="<table style='width: 100%'><tr><td> <input type='Text'/></td></tr></table>";
}
</script>
</head>
<body>
<div id="myAnchor">
</div>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>

button action with jQuery Mobile,

Having trouble constructing a button dynamically with jQuery Mobile. Copy and run. See notes in code.
<!DOCTYPE html>
<html>
<head>
<title>MSC Pre-Close Application</title>
<meta charset="utf-8"/>
<!-- standard Jquery/jQuery Mobile Libraries -->
<script src="jquery.mobile/jquery.js"></script>
<script src="jquery.mobile/jquery.mobile.js"></script>
<link rel="stylesheet" href="jquery.mobile/jquery.mobile.css" />
<BR/>
<div data-role="page" id="mainmenu">
<div data-role="header" data-position="inline">
<h1>Main Menu</h1>
</div>
<div class="ui-body ui-body-c">
<div data-role="content">
<div class="ui-block-a"><button id="click_me" type="submit" data-theme="a" data-icon="home">Click me to change the button to my right</button></div>
<div class="ui-block-a"><button class="cl_pre_phone1" type="submit" rel="external" data-theme="a" data-icon="home">Primary Phone</button></div>
<script>
$(document).ready(function()
{
// this changes the label but not the href action.
$(".cl_pre_phone1").html("<a href='google.com'> Google</a>");
$("#click_me").click(function() {
alert("this should change the text and href of the button!");
// here I would like to change the value as well as the href action, but it does not work.
$(".cl_pre_phone1").html("<a href='yahoo.com'>Yahoo</a>");
//$(".cl_pre_phone1").append("<a href='yahoo.com'>Yahoo</a>");
//$(".cl_pre_phone1").append("<a href='yahoo.com'>Yahoo</a>").reload(true);
});
});
</script>
You're getting messed up by the enhancement which jQM does. Your button is getting rewritten to:
<span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Primary Phone</span>
<span class="ui-icon ui-icon-home ui-icon-shadow"></span></span>
<button class="cl_pre_phone1 ui-btn-hidden" type="submit" data-theme="a" data-icon="home" aria-disabled="false">Primary Phone</button>
One way round this would be to change the call inside the callback to:
$(".cl_pre_phone1").attr("href", "http://yahoo.com").parent().find(".ui-btn-text").text("Yahoo");
or you could replace the whole ui-block-a div.