Use jQuery to set select box value to first option
I am dynamically populating a select box with options. When I do this, I
want the value of the select box to be the value of the first option (a
'default option', if you like). Sounds really simple, but I just can't get
it to work.
var myElement = $('select[name="myName"]');
.... tried the following three variations
// myElement.find('option').first().prop('selected', 'selected');
// myElement.val(myElement.find('options').first().val());
myElement.prop('selectedIndex', 0);
...but the following line gives a blank alert
alert(myElement.val());
Where am I going wrong?
Thursday, 22 August 2013
Reading SIO_KEEPALIVE_VALS fields on a Windows socket (for keepalive idle and interval times)
Reading SIO_KEEPALIVE_VALS fields on a Windows socket (for keepalive idle
and interval times)
Given a Windows socket, I want to determine which values it is using for
the TCP keepalive idle time and the TCP keepalive interval time (roughly
equivalent to the TCP_KEEPIDLE and TCP_KEEPINTVL settings on Berkeley
sockets).
I see that you can set these values using a WSAIoctl call (see
http://msdn.microsoft.com/en-us/library/windows/desktop/dd877220%28v=vs.85%29.aspx
). However, there does not appear to be any API for reading their current
values. I tried calling WSAIoctl with a populated output parameter but
NULL input parameter, like this:
DWORD bytes_returned;
struct tcp_keepalive keepalive_opts;
int rv = WSAIoctl(socket, SIO_KEEPALIVE_VALS, NULL, 0, &keepalive_opts,
sizeof(keepalive_opts), &bytes_returned, NULL, NULL);
But this returns me a WSAEFAULT ("The system detected an invalid pointer
address in attempting to use a pointer argument in a call.").
I could call WSAIoctl with both an input and an output parameter, but I
don't want to set the values, I just want to read them. And as far as I
can tell, providing any non-NULL input parameter would cause the
parameters to be set to whatever values happen to be in that memory space
(defined by the struct tcp_keepalive; again see
http://msdn.microsoft.com/en-us/library/windows/desktop/dd877220%28v=vs.85%29.aspx
).
The above also highlights another problem with not knowing what the
current values are: I can't set just one of the keepalive idle time or the
keepalive interval time - I must blow away both (unknown) values at the
same time since they're both members of the struct I'm required to
provide.
I know that I could assume things about what values are set based on
Windows documentation, but I'd rather not assume. I see that
http://technet.microsoft.com/en-us/library/bb726981.aspx#EDAA defines
KeepAliveInterval and KeepAliveTime default values. However, the
Parameters folder in my Windows 7 registry does not contain either of
those keys, so I really have to rely on the documentation being 100%
correct here (to know the default values a socket will receive), which is
much worse than programmatically retrieving them (even retrieving them
from the registry might be ok, but the above experience shows I can't).
Is there any way to get the current TCP keepalive idle time and the TCP
keepalive interval time values for a Windows socket?
and interval times)
Given a Windows socket, I want to determine which values it is using for
the TCP keepalive idle time and the TCP keepalive interval time (roughly
equivalent to the TCP_KEEPIDLE and TCP_KEEPINTVL settings on Berkeley
sockets).
I see that you can set these values using a WSAIoctl call (see
http://msdn.microsoft.com/en-us/library/windows/desktop/dd877220%28v=vs.85%29.aspx
). However, there does not appear to be any API for reading their current
values. I tried calling WSAIoctl with a populated output parameter but
NULL input parameter, like this:
DWORD bytes_returned;
struct tcp_keepalive keepalive_opts;
int rv = WSAIoctl(socket, SIO_KEEPALIVE_VALS, NULL, 0, &keepalive_opts,
sizeof(keepalive_opts), &bytes_returned, NULL, NULL);
But this returns me a WSAEFAULT ("The system detected an invalid pointer
address in attempting to use a pointer argument in a call.").
I could call WSAIoctl with both an input and an output parameter, but I
don't want to set the values, I just want to read them. And as far as I
can tell, providing any non-NULL input parameter would cause the
parameters to be set to whatever values happen to be in that memory space
(defined by the struct tcp_keepalive; again see
http://msdn.microsoft.com/en-us/library/windows/desktop/dd877220%28v=vs.85%29.aspx
).
The above also highlights another problem with not knowing what the
current values are: I can't set just one of the keepalive idle time or the
keepalive interval time - I must blow away both (unknown) values at the
same time since they're both members of the struct I'm required to
provide.
I know that I could assume things about what values are set based on
Windows documentation, but I'd rather not assume. I see that
http://technet.microsoft.com/en-us/library/bb726981.aspx#EDAA defines
KeepAliveInterval and KeepAliveTime default values. However, the
Parameters folder in my Windows 7 registry does not contain either of
those keys, so I really have to rely on the documentation being 100%
correct here (to know the default values a socket will receive), which is
much worse than programmatically retrieving them (even retrieving them
from the registry might be ok, but the above experience shows I can't).
Is there any way to get the current TCP keepalive idle time and the TCP
keepalive interval time values for a Windows socket?
Initialize a KnockOut model with json
Initialize a KnockOut model with json
I want to init a Knockout model with as json received from the server.
For the moment, I have this html :
<div class='liveExample'>
<p>First name: <input data-bind='value: firstName' /></p>
<p>Last name: <input data-bind='value: lastName' /></p>
<h2>Hello, <span data-bind='text: fullName'> </span>!</h2>
</div>
And this JavaScript :
// Here's my data model
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
return this.firstName() + "/" + this.lastName();
}, this);
};
var viewModel = new ViewModel();
data = { firstName: 'test', lastName: 'bla' }; //received from the server
side
viewModel.firstName(data.firstName)
viewModel.lastName(data.lastName)
ko.applyBindings(viewModel);
It works, but if I have more fields, it can painful.
I tried to use the mapping plugin like this :
var viewModel = new ViewModel();
data = { firstName: 'test', lastName: 'bla' }; //received from the server
side
viewModel = ko.mapping.fromJSON(data, viewModel)
ko.applyBindings(viewModel);
In this case, the method fullName is undefined.
I tried to do this :
viewModel = ko.mapping.fromJSON(viewModel, data)
And the lastName and firstName are undefined.
Is there a simple solution to do this?
Thanks!
I want to init a Knockout model with as json received from the server.
For the moment, I have this html :
<div class='liveExample'>
<p>First name: <input data-bind='value: firstName' /></p>
<p>Last name: <input data-bind='value: lastName' /></p>
<h2>Hello, <span data-bind='text: fullName'> </span>!</h2>
</div>
And this JavaScript :
// Here's my data model
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
return this.firstName() + "/" + this.lastName();
}, this);
};
var viewModel = new ViewModel();
data = { firstName: 'test', lastName: 'bla' }; //received from the server
side
viewModel.firstName(data.firstName)
viewModel.lastName(data.lastName)
ko.applyBindings(viewModel);
It works, but if I have more fields, it can painful.
I tried to use the mapping plugin like this :
var viewModel = new ViewModel();
data = { firstName: 'test', lastName: 'bla' }; //received from the server
side
viewModel = ko.mapping.fromJSON(data, viewModel)
ko.applyBindings(viewModel);
In this case, the method fullName is undefined.
I tried to do this :
viewModel = ko.mapping.fromJSON(viewModel, data)
And the lastName and firstName are undefined.
Is there a simple solution to do this?
Thanks!
variable is not passed by reference
variable is not passed by reference
I have compile and run my program correctly but it seems that the variable
sum is not passed by reference and it still got 0. Any help here is the
code.
#include "VendingMachine.h"
int VendingMachine::MakeSelection(int ItemPrice[], int NumItems[],int &sum){
int total_cost = 0;
cout << "Enter your choice: ";
cin >> choice;
if(choice >= 1 && choice <= 9){
while (choice != 0){
NumItems[(choice-1) % 10]--;
total_cost += ItemPrice[(choice-1)%10];
choice/=10;
}
}
}
Main.cpp
#include "VendingMachine.h"
int main()
{
int Denominations = 5;
int Coins[] = {100, 50, 20, 10, 5};
int NumCoins[] = {10, 10, 10, 10, 10}; //assume we have 10 coins of
each denomination
const int Items = 9;
int sum, deposit;
int ItemPrice[ ] = { 75, 120, 120, 100, 150, 95, 110, 50, 120 };
//price in cents
int NumItems[ ] = { 10, 10, 10, 10, 10, 10, 10, 10, 10 };
VendingMachine caller;
caller.ShowMenu();
cout << endl;
cout << "Enter your money: ";
cin >> deposit;
caller.MakeSelection(ItemPrice,NumItems,sum);
cout <<"The total cost is " << sum << endl;
system("PAUSE");
return 0;
}
Vending.h
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int total_cost;
int Coins[5];
int NumCoins[5];
int ItemPrice[9];
int NumItems[9];
class VendingMachine{
public:
int MakeSelection(int ItemPrice[], int NumItems[],int &sum);
void ReturnChange(int& input,int& sum, int Coins[],int NumCoins[]);
void ShowMenu();
void DisplayErrorMessage(int error);
void PrintConfidentialInformation(int Denominations, int Items, int
Coins[], int NumCoins[], int ItemPrice[] , int NumItems[]);
private:
int choice;
string Password;
int deposit2;
};
The total cost should return a value of sum in the MakeSelection cpp but
still it returns a 0..??
I have compile and run my program correctly but it seems that the variable
sum is not passed by reference and it still got 0. Any help here is the
code.
#include "VendingMachine.h"
int VendingMachine::MakeSelection(int ItemPrice[], int NumItems[],int &sum){
int total_cost = 0;
cout << "Enter your choice: ";
cin >> choice;
if(choice >= 1 && choice <= 9){
while (choice != 0){
NumItems[(choice-1) % 10]--;
total_cost += ItemPrice[(choice-1)%10];
choice/=10;
}
}
}
Main.cpp
#include "VendingMachine.h"
int main()
{
int Denominations = 5;
int Coins[] = {100, 50, 20, 10, 5};
int NumCoins[] = {10, 10, 10, 10, 10}; //assume we have 10 coins of
each denomination
const int Items = 9;
int sum, deposit;
int ItemPrice[ ] = { 75, 120, 120, 100, 150, 95, 110, 50, 120 };
//price in cents
int NumItems[ ] = { 10, 10, 10, 10, 10, 10, 10, 10, 10 };
VendingMachine caller;
caller.ShowMenu();
cout << endl;
cout << "Enter your money: ";
cin >> deposit;
caller.MakeSelection(ItemPrice,NumItems,sum);
cout <<"The total cost is " << sum << endl;
system("PAUSE");
return 0;
}
Vending.h
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int total_cost;
int Coins[5];
int NumCoins[5];
int ItemPrice[9];
int NumItems[9];
class VendingMachine{
public:
int MakeSelection(int ItemPrice[], int NumItems[],int &sum);
void ReturnChange(int& input,int& sum, int Coins[],int NumCoins[]);
void ShowMenu();
void DisplayErrorMessage(int error);
void PrintConfidentialInformation(int Denominations, int Items, int
Coins[], int NumCoins[], int ItemPrice[] , int NumItems[]);
private:
int choice;
string Password;
int deposit2;
};
The total cost should return a value of sum in the MakeSelection cpp but
still it returns a 0..??
How do I find ARM Linux entry point when it fails to uncompress?
How do I find ARM Linux entry point when it fails to uncompress?
I am trying to boot Linux via U-boot on a custom board with i.MX6 (CPU
core is ARM Cortex A9)
We seem to have ported Das U-Boot successfully. But booting Linux fails at
the last U-Boot message: "Starting kernel ..."
Here is my relevant environment:
bootargs=console=ttymxc1,115200 vmalloc=400M root=/dev/mmcblk0p1 rootwait
consoleblank=0 earlyprintk video=mxcfb0:dev=lcd,LCD-ORTUS,if=RGB24
video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24 calibration tsdev=tsc2004
fbmem=10M,28M
bootcmd=ext2load mmc 0:1 10800000 /boot/uImage ; bootm 10800000
The boot output is
Loading file "/boot/uImage" from mmc device 0:1 (xxa1)
4043552 bytes read
## Booting kernel from Legacy Image at 10800000 ...
Image Name: Linux-3.0.35
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4043488 Bytes = 3.9 MB
Load Address: 10008000
Entry Point: 10008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
When I objdump the kernel, at address 80008000, I see the entry point at
arch/arm/kernel/head.S, and not arch/arm/boot/compressed/head.S
What I see is, the kernel does not even decompress. I tried adding some
register manipulation code to signal GPIOs in compressed/head.S with no
response.
My question is, how can I make sure U-Boot is calling the correct entry
point?
The exact same kernel binary successfully boots on Freescale's reference
board, using the same U-Boot commands.
I am trying to boot Linux via U-boot on a custom board with i.MX6 (CPU
core is ARM Cortex A9)
We seem to have ported Das U-Boot successfully. But booting Linux fails at
the last U-Boot message: "Starting kernel ..."
Here is my relevant environment:
bootargs=console=ttymxc1,115200 vmalloc=400M root=/dev/mmcblk0p1 rootwait
consoleblank=0 earlyprintk video=mxcfb0:dev=lcd,LCD-ORTUS,if=RGB24
video=mxcfb1:dev=hdmi,1280x720M@60,if=RGB24 calibration tsdev=tsc2004
fbmem=10M,28M
bootcmd=ext2load mmc 0:1 10800000 /boot/uImage ; bootm 10800000
The boot output is
Loading file "/boot/uImage" from mmc device 0:1 (xxa1)
4043552 bytes read
## Booting kernel from Legacy Image at 10800000 ...
Image Name: Linux-3.0.35
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4043488 Bytes = 3.9 MB
Load Address: 10008000
Entry Point: 10008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
When I objdump the kernel, at address 80008000, I see the entry point at
arch/arm/kernel/head.S, and not arch/arm/boot/compressed/head.S
What I see is, the kernel does not even decompress. I tried adding some
register manipulation code to signal GPIOs in compressed/head.S with no
response.
My question is, how can I make sure U-Boot is calling the correct entry
point?
The exact same kernel binary successfully boots on Freescale's reference
board, using the same U-Boot commands.
data from jTextfield and display to the jTable and textfile
data from jTextfield and display to the jTable and textfile
i need help , im a Java newbie. i have a table and has a 3 Columns ID ,
Name , Age. Every Data inputted at the jTextfield will Display to the
Table. The data Display in the Table will also Display at the Textfiles.
i need help , im a Java newbie. i have a table and has a 3 Columns ID ,
Name , Age. Every Data inputted at the jTextfield will Display to the
Table. The data Display in the Table will also Display at the Textfiles.
Wednesday, 21 August 2013
A constructor in an interface?
A constructor in an interface?
I'm reading an article about inner class. I found an example that
demonstrates anonymous inner class (mentioned below).
button1 = new JButton();
button2 = new JButton();
...
button1.addActionListener(
new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
// do something
}
}
);
According to the example it creates an inner class for responding to a
button using ActionListener interface. As I know an interface does not
have a constructor. But I'm wondering, how they call a constructor.
"new java.awt.event.ActionListener(){ }"
I'm reading an article about inner class. I found an example that
demonstrates anonymous inner class (mentioned below).
button1 = new JButton();
button2 = new JButton();
...
button1.addActionListener(
new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
// do something
}
}
);
According to the example it creates an inner class for responding to a
button using ActionListener interface. As I know an interface does not
have a constructor. But I'm wondering, how they call a constructor.
"new java.awt.event.ActionListener(){ }"
Subscribe to:
Posts (Atom)