element.onclick= aFunction() does not call the function when element (in this case a <SPAN> element) is clicked.
This question has been answered for JavaScript (question by Nick Van Hoogenstyn), but how do you do the same sort of thing for VBScript? The reason why I'm using VBScript instead of JavaScript is that I'm creating an HTA and using VBScript for the file access activities within it.
This
demonstrates that this simple code:
<html>
<head>
<Title>spanclick</Title>
<hta:application id="spanclick" scroll = "no">
<script type="text/vbscript">
Function onSpanClick(oElm)
MsgBox oElm.tagName & " onSpanClick clicked"
End Function
</script>
</head>
<body>
<span onclick="onSpanClick Me">onSpanClick</span>
</body>
</html>
'works' by putting the function name into the onclick attribute of the span element and passing the element (Me) to the function.
VBScript is little bit different form Javascript in Syntax
see the sample
<script language="vbscript">
sub cmdBtn_Click()
msgbox("Click!!!")
end sub
</script>
<input type="button" name="cmdBtn" value="Click Me!" onclick ="vbscript:cmdBtn_Click">
Related
How to pass data from child (mvc) window to parent window?
a few seconds ago|LINK
I have a situation where I need to pass some data from a child (MVC) page to parent window. But in this case the user does not need any interaction with the child window. The child window will simply open from the parent via a button click, to run a server-side process and return some code value to parent window and will need to close.
I am unsure how to pass data from a mvc page controller to a parent page and also how to close the child window itself..
Any suggestions?
I think this may answer your question:
parent window - parent.asp
<html>
<script language="javascript">
function openwindow() {
retval=window.showModalDialog("child.asp")
document.getElementById('passedChild').value=retval
}
</script>
<body>
<form name=frm>
<input name="passedChild" id="passedChild" type=text>
<input type=button onclick="javascript:openwindow()" value="Open Child">
</form>
</body>
</html>
child window - child.asp
<html>
<head>
<%
'... i work in classic asp so can run asp here and then flow into JS for retrun
%>
//
<script language="javascript">
function changeparent() {
window.returnValue="passed value"
window.close()
}
</script>
</head>
<body>
<form>
<input type=button onclick="javascript:changeparent()" value="Change passedChild">
</form>
</body>
</html>
I have a simple file to test onclick function which I copied straight from w3schools' example. It works fine in the Tryit editor, but the button with the onclick function does nothing when I place it on my server.
<!DOCTYPE html>
<html>
<head>
<script>
function open_win()
{
window.open("http://www.<valid address>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Open Window" onclick="open_win()">
</form>
</body>
</html>
Where should I look first?
It does work for me and it is valid code, so I don't know why it's not working for you. But here's an alternative:
<input ... onclick="window.open('http://www.<valid address>');">
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If it still doesn't work then check if you have JavaScript enabled in the browser you are using to access your server.
I want to fire a button's click event when pressing ENTER inside a input and I find it quite difficult with AngularJS.
My view (simplified, updated):
<!doctype html>
<html lang="en" ng:app="test">
<head>
<meta charset="utf-8" />
<title>Test</title>
<link rel="stylesheet" href="css/app.css" />
</head>
<body ng-controller="TestController">
<button ng-click="onButton1Click()" class="btn1">Click Me</button>
<button ng-click="onButton2Click()" class="btn2">Don't click me</button>
<script src="lib/jquery/jquery.js"></script>
<script src="lib/angular/angular.js"></script>
<script src="js/testcontroller.js"></script>
</body>
</html>
My controller for this view:
'use strict';
angular.module('test', [])
.controller('TestController', ['$scope',
function($scope) {
$scope.onButton1Click = function() {
alert("Hello");
}
$scope.onButton2Click = function() {
$('.btn2').click();
}
}])
I simplified all the code to this. When I click on btn2 I get this error
$apply already in progress
No, I can't call $scope.onButton1Click() directly, I must simulate the btn1 click.
You mentioned
fire a button's click event when pressing ENTER inside a input
So if it is safe to assume that you can have a form I would prefer using ng-submit as shown below.
<form ng-submit="clickEventFunction()">
<input type="text"/>
<button type="submit">Click</button>
</form>
Note button type should be submit.
This took me a while to figure out (lots of fiddles).
<form id="nowsorting" ng-submit="getData(sc_user)">Now sorting the Soundcloud likes of <input type="text" ng-model="sc_user"><input type="submit" value="Sort"></form>
Make a form and use ng-submit to fire the event (likely a function).
Then create two inputs (one is "text" and the other "submit").
Then pushing enter should fire the ng-submit event/function.
I think, you just have to call your $scope.onButtonClick()
Please check this Plunker
$scope.onKeyPress = function($event) {
if ($event.keyCode == 13) {
$scope.onButtonClick();
}
};
I'm trying to make my own tumblr search (tags only) since their own search function doesn't actually work.
So I'm nearly there. It works, but I need the search field to keep the value of what the user searched for.
So if I search for "foobar", it loads the tumblr.com/tagged/foobar directly into my tumblr.com, but the search field still contains the term "foobar"
Here is my working code except for the code where I'm trying to insert the previous search term into the newly loaded
Thanks in advance.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
jQuery(function($) {
$('#syndex').keydown(function(event) {
if (event.keyCode == '13') {
var syndex = $('input:text').val();
$('body').load("http://syndex.me/tagged/"+ syndex);
$(this).val(syndex); //this is what's not working
}
});
});
</script>
</head>
<body>
<div id="logo">
<input id="syndex" type="text"/>
</div>
</body>
</html>
You need to put this into the complete function which can be passed as a parameter to load.
http://api.jquery.com/load/
Load makes an AJAX call which is asynchronous. You are trying to set the value prior to the content being loaded.
$('body').load("http://syndex.me/tagged/"+ syndex,function(){
$('input:text').val(syndex);
});
its kind of silly question. but i dont know what mistake i am making. if any one could help.
<html>
<head>
<script type="text /vbscript">
function zips(s)
document.write(s)
end function
</script>
</head>
<body>
<script type="text/vbscript">
dim x,y
x="sushant"
<button onclick="zips(x)" id=button1 name=button1>clickme</button>
</script>
</body>
</html>
sorry i dont know how to format it. but i am no getting the desired output. any help is very much appreciated
Your button tag should be outside of the script tag.
<script type="text/vbscript">
dim x,y
x="sushant"
</script>
<button onclick="zips(x)" id=button1 name=button1>clickme</button>
The button is not part of the script but part of the HTML.