Wednesday, May 2, 2012

Javascript function not being called at all

I made the following small Javascript script to enable some form elements on my page:



function unHide()
{
if($('#UserName').val() == "")
{
alert('Please Enter a User Name first');
}
else
{
$('#radio-choice-1').checkboxradio('enable');
$('#radio-choice-2').checkboxradio('enable');
$('#radio-choice-1-board').checkboxradio('enable');
$('#radio-choice-2-board').checkboxradio('enable');
$('#TransNum').textinput('enable');
$('#UserContinue').remove();
$('#nextButton').show();
}
}


The problem is, this isn't being called when the correct button is clicked. Even the alert doesn't show up. Here is the HTML:



<label for="UserName" style="vertical-align: top;">User Name:</label>
<input type="text" name="UserName" id="UserName" placeholder="Ex: LesniakBjEVS101" />

...

<a data-role="button" data-icon="check" data-mini="true" id="UserContinue"
style="float:right;" onclick="javascript:unHide(); return false;">Continue...</a>

...

<section id="nextButton" hidden>
<a href="salamanderSelect.html" data-role="button" data-icon="forward"
data-mini="true" style="float:right;">Next</a>
</section>


The problem I am encountering is when I click on the submit button, absolutely nothing happens. I am not getting any feeback from the Javascript, nor anything.



Any help would be greatly appreciated!
Thanks!



Edit:



After trying out suggestions, I still am unable to get the javascript to do anything. I have tried multiple browsers, but still nothing.



And I just had this working yesterday too...without any changes to the code too



Edit 2:



Apparently it works if my script is the last thing in the HTML file, even outside of the tags.





How do I make this SQL code faster?

any suggestions on how to make this query faster?



Also the field names are: id, sku, description, price, quantity, weight, search, pro



sorry it ms-access



SELECT *
FROM catalog
WHERE sku LIKE '1W%'
AND sku NOT IN (SELECT TOP 25 sku
FROM catalog
WHERE sku LIKE '1W%' )




Output from an Exception class in App_Code

I am trying to see what exception is happening on my dev clients devserver (our servers are fine) and I have an TestException.cs class that handles the most of my exceptions from my sql statement class.



I have a method like so:



StringBuilder errorMessages = new StringBuilder();

for (int i = 0; i < innerException.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + innerException.Errors[i].Message + "\n" +
"LineNumber: " + innerException.Errors[i].LineNumber + "\n" +
"Source: " + innerException.Errors[i].Source + "\n" +
"Procedure: " + innerException.Errors[i].Procedure + "\n");
}

//Console.WriteLine(errorMessages.ToString());
Response.Clear();
Response.Write("FAILURE");
Response.End();


But the Response.XX won't compile and if I use console.writeline when it hits it on the client server, the browser gets a connection lost webpage.



Is there a better way to do this?





Retaining route details on MVC Form Postback

I have a basic MVC form which is accessed through a GET Action with 3 string parameters pulled from the route.



[HttpGet]
public ActionResult Application(string x, string y, string z)
{
//create model, setup form, etc...

return View(model);
}


The route to access this form is configured as follows:



routes.MapRoute("Application", 
"application/{x}/{y}/{z}",
new
{
controller = "Application",
action = "Application",
x = "",
y = "",
z = ""
});


And the form is configured as follows:



Html.BeginForm("Application", "Application", FormMethod.Post)


All of this works until I click submit on the resulting form. From a routing perspective the correct POST Action is called and the Model is bound correctly. The problem is I have lost all the x/y/z route information which I still need. How can I preserve the route information?



I've tried a couple things:




  • Added route details to the Form in Hidden fields which are added to the form content correctly but never get returned in the Model on postback

  • Tried using the RouteValueDictionary overload for Html.BeginForm but can't figure out how to make it work. I may just need a proper example of how to use it and how to access the state from the Controller





Parsing & Sorting csv file by Line

Got this csv file of my jump logbook and wish to sort within each block (Jump Record), so that intructor is listed first, student second and optional cameraman last.
Current they are written in various order.



Was thinking of reading and assigning each line of the block into vars and then printing using the blank line as a loop contron. Am I on the right track?
Would prefer solution help in C++ (little bit of exp. and a compiler setup), but am flexi and looking to really get into the nuts and bolt of any reccommended language this summer. Possible Python or any one with a good book intro to CompSci.



Any advice & ref much appreciated!



first col is role: 1,2,3.



role(1,2,3),date (yyymmdd), aircraft-liftnumber, name
role 1 is a tandem instructor,
role 2 is a student,
role 3 freefall camera (optional)



1,20100124,C206WR-L1,MAC PETE



2,20100124,C206WR-L1,HOWARD STEPH



3,20100124,C206WR-L1,JONES DAVE



,,,



2,20100124,C206WR-L3,ALLSOP BEX



1,20100124,C206WR-L3,MAC PETE



3,20100124,C206WR-L3,JONES DAVE



,,,



1,20100124,C206WR-L2,MAC PETE



3,20100124,C206WR-L2,LAUER FINCH



2,20100124,C206WR-L2,JONES DAVE



,,,



1,20100124,C206WR-L4,MAC PETE



3,20100124,C206WR-L4,LAUER FINCH



2,20100124,C206WR-L4,JONES DAVE



,,,



2,20100124,C206WR-L4,SMITH JOHN



1,20100124,C206WR-L4,MAC PETE



,,,



2,20100124,C206WR-L5,BROWN CLAIRE



3,20100124,C206WR-L5,JONES DAVE



1,20100124,C206WR-L5,MAC PETE





How can i switch to settings from my app?

I would like to switch my user to settings app if he answered by no for using his localisation. i'm using an alert view to do that





How Mange Memory to solve NotEnoughMemoryException in C#

My memory is 4GB(2.99GB usable, but I don't know why).
When use Bluebit Library to deal with Matrix in project C# Visual Studio 2010, and when execute code in Windows Form Application and after connect with Database, appear NotEnoughMemoryException (There is not enough memory to continue the execution) and physically memory used is 2.14GB , but when use code alone in Console Application doesn't appear any exception.



StreamWriter aWr = new StreamWriter("aMatrix.mtx");
Matrix aMatrix = new Matrix(termsList.Count, Docs.Count);
/////load aMatrix from DataBase and aMatrix[8200, 40]

SVD svd = new SVD(aMatrix);
StreamWriter sWr = new StreamWriter("sMatrix.mtx");
Matrix S = svd.S.SubMatrix(0, k - 1, 0, k - 1);
for (int row = 0; row < S.Rows; row++)
{
for (int col = 0; col < S.Cols; col++)
sWr.Write(S[row, col] + "\t");
sWr.Write("\n");
}
sWr.Close();

StreamWriter uWr = new StreamWriter("uMatrix.mtx");
Matrix U = svd.U;
nt endRaws = U.Rows - 1;
U = U.SubMatrix(0, endRaws, 0, k - 1);
for (int row = 0; row < U.Rows; row++)
{
for (int col = 0; col < U.Cols; col++)
uWr.Write(U[row, col] + "\t");
uWr.Write("\n");
}
uWr.Close();

StreamWriter vWr = new StreamWriter("vMatrix.mtx");
Matrix V = svd.V;
endRaws = V.Rows - 1;
V = V.SubMatrix(0, endRaws, 0, k - 1);
for (int row = 0; row < V.Rows; row++)
{
for (int col = 0; col < V.Cols; col++)
vWr.Write(V[row, col] + "\t");
vWr.Write("\n");
}
vWr.Close();

StreamWriter vtWr = new StreamWriter("vtMatrix.mtx");
Matrix VT = new Matrix(V.Cols, V.Rows);
for (int row = 0; row < V.Rows; row++)
for (int col = 0; col < V.Cols; col++)
VT[col, row] = V[row, col];

for (int row = 0; row < VT.Rows; row++)
{
for (int col = 0; col < VT.Cols; col++)
vtWr.Write(VT[row, col] + "\t");
vtWr.Write("\n");
}
vtWr.Close();


How I can Manage my Memory?





Java for loop not completing properly

Ok, so I'm trying to add an array of 64 JButtons to a JFrame with and 8 by 8 grid layout (chess board type thing). Here's the relevant code section:



public class othello implements ActionListener{
int [][] board = new int[8][8];
JFrame window = new JFrame();
JButton[] buttons = new JButton[64];

public othello(){

window.setSize(400,400);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new GridLayout(8,8));
window.setVisible(true);
for (int i=0;i<64;i++){
buttons[i] = new JButton("");
buttons[i].addActionListener(this);
window.add(buttons[i]);
}
for (int i=0;i<8;i++){
for (int j=0;j<8;j++){
board[i][j]=2;
}
}
board[3][3]=0;board[4][4]=0;
board[3][4]=1;board[4][3]=1;
}

public void actionPerformed(ActionEvent e){
for (int i=0;i<8;i++){
for (int j=0;j<8;j++){
if(e.getSource()==buttons[i]){
buttons[i].setEnabled(false);
board[i][j]=1;
check();
}
}
}
}

public static void main (String[] args){
new othello();
}


}



What this code results in is a seemingly random number of buttons actually being added. Occasionally it adds all 64, more commonly it adds perhaps half or so, it always starts properly but stops at an arbitrary point (I tested by having the button labels count up).



I added some println's to see if the loop itself was actually completing, no problem there, it's going round the loop all 64 times, it just stops adding buttons at some point.



I'm something of a beginner at Java so I'm sure it's something really simple and stupid, but I currently have no idea what's going wrong. Can anyone help?



Edited for more code.





C++ Moving a char in a 2d array

I have to make a game for a university project. In this game i have to have a character that can be moved in the 2d grid by use of keyboard input. I can only get the character to move one block to the left, right, up,down and that all. it does not allow me for example to move two positions to the left from the original.



Here is my code:



void Opstical(char**array,int row,int col,int direction) {
int a(0);
int b(1);
//here is my problem where i cant get it to move
//more than one block away from the original spot.
//char 2 i want to move

array[a][b] = 2;
if(direction == 4) {
array[a][b]=array[a][b-1]=2;
}
if(direction == 6) {
array[a][b]=array[a][b+1]=2;
}
if(direction == 8) {
array[a][b]=array[a-1][b]=2;
}
if(direction == 2) {
array[a][b]=array[a+1][b]=2;
}

for(int i = 0;i < row ; i++) {
for(int c = 0; c < col; c++) {
cout << array[i][c]<<" ";
}
cout <<endl<<endl;
}
}


Thanks.





Plot 3D in java

I wanna know what is the most efficient way of plotting 3D scatter points cloud using current available 3D java libraries. so that the user can drag the 3D plot and rotate it etc. I wanna make my work available on line too. So I would like to get suggestions for 3D Java for web applications to plot the points 3D in the browser.



Is the Jzy3d still the best choice?





removing unneeded query from generated url string in php

I have the following string generating mp3 urls for a music player on my site.



<?php echo $song->getTitle() ?>


which results in /public/music_song/df/74/746b_2112.mp3?c=ec1e



I would like to remove the query from the string
resulting in /public/music_song/df/74/746b_2112.mp3



I've looked into how to split the url, but I'm nowhere near being a php genius just yet so I dont know weather to split or use preg_replace or how the heck to incorporate it into my existing string.



I have to get rid of these queries, they are unneeded and crashing my databases on a daily basis.





Some questions about AsyncTask

As far as I understand in an AsyncTask only doInBackground is executed in its own task. All other methods - e.g. onPostExecute - are executed in the Activity task.

Is it true, that onPostExecute and let's say onCofigurationChanged are in fact synchronized?



Does the system clean up a task, if it is finished or canceled and no longer referenced?





How to attach components programmatically to GroupBox in C#

I have program which creates groupbox and label automatically. However I can't seem to attach label to groupbox as it doesn't recognize its name. It would be also helpful if the name could be dynamic, e.g. groupbox[i] where i is changing integer.



                    //instantiate and configure the groupbox
myarray.Add(new GroupBox().Name="test[i]");
System.Drawing.Point p3 = new System.Drawing.Point(8, 350 + alistcount * 41);
(myarray[count+ 2] as GroupBox).Location = p3;
(myarray[count+ 2] as GroupBox).Size = new System.Drawing.Size(340, 100);
(myarray[count+ 2] as GroupBox).Text = code;
tabPageLevel4.Controls.Add(myarray[count+ 2] as GroupBox);

//instantiate and configure the text box
myarray.Add(new Label());
System.Drawing.Point p2 = new System.Drawing.Point(12, 30);
(myarray[count+1] as Label).Location = p2;
(myarray[count+ 1] as Label).Size = new System.Drawing.Size(60, 30);
(myarray[alistcount + 1] as Label).Text = name;
test.Controls.Add(myarray[count+ 1] as Label);




How do you add an index field to Linq results

Lets say I have an array like this:



string [] Filelist = ...


I want to create an Linq result where each entry has it's position in the array like this:



var list = from f in Filelist
select new { Index = (something), Filename = f};


Index to be 0 for the 1st item, 1 for the 2nd, etc.



What should I use for the expression Index= ?





Exclude PictureBox From TransparencyKey

I have a form set TransparencyKey = Color.White, backColor = Color.White and a PictureBox in it with an image that has a white portion. Is it possible not to make the PictureBox to have transparent on the white portion?



See Image

enter image description here



Any alternative solution if that's not possible..





Using IIS 7.5 with Tomcat and ARR to re-write URL

I've tried searching but can't seem to get the answer I need.



I have some webservices managed by IIS. However, we need to host a web application run on Tomcat on the same server. The solution it seems, is to create a Server Farm in IIS, and this works for the most part.



The url we normally use to access the app run on Tomcat is localhost:8080.
By setting up the server farm in IIS, I've managed to get http://localhost to redirect to the same app. However, this creates a conflict with another app, so I want a custom path like http://localhost/Webapp/ to redirect there. How do I accomplish this?





get the PORT and the HOST of a specified USB connected hardware

I would like to get in c# the Host and the Port of a docked usb hardare ( especially an usb key )



the information is aviable under the Windows's device manager after selected a given usb hardware



thanks





How to implement a data historian (OPC)?

A friend has asked if I coudl implement a data historian. I am busy doing research, googling around, reading UPC Unified Architecture - but it's a lot to get through, so I will ask if anyone here has ever gone down that road (while still continuing my research).



Approx how many man months for a 20+ year developer (or two) to get at least a demonstratable working prototype - and how long to completion?



Which programming language? Is C++ godd, or what?



What resouces are available to me? (I thought I saw an Open OPC framework, but can't find it again). Any FOSS, libraries or free ecode which I can base upon? Maybe a sourceForge project?



How best to test?



Any other hints?





time functions in c++

I need to calculate the number of seconds passed since the beginning of the year.
I'm a little confused with all the time functions I found.



I thought of maybe using timer (finding seconds from 1/1/1970) but how can I continue with this one?





Tabs after closing dialog window

I am working with a form in JQuery. I have a dialog box that I need to be able to close with "ESCAPE", which I have done. The issue is that tab index does no seem to function correct. What I have is a dialog box in between two input textboxes. Ideally what I would like to happen is for the use to tab to first input box, enter input. Tab to the message icon that opens the dialog box, view the message, close the message and then be on the next input. What happens is that it take me to the very first hyper link in the page. Any ideas on how to set the dialog box to place the cursor on the second text box once the dialog is closed?



So I have the following code but it fires the event on page load and not when I close the dialog, any ideas?



    var $dialog = $('<div></div>')
.html('test message1')
.dialog({
autoOpen: false,
resizable: false ,
closeOnEscape: true,
title: 'Account Message1',
close: $("#shipToContainer").find("input").focus(),
});