> please.............i'd be very very grateful to anyone who cud help me out, before 25th
> December!
No, we won't help you fool / deceive your trainer.
Sorry we won't be able to send the code but 'Merry Christmas' in advance. Have a nice day.
> please.............i'd be very very grateful to anyone who cud help me out, before 25th
> December!
No, we won't help you fool / deceive your trainer.
Sorry we won't be able to send the code but 'Merry Christmas' in advance. Have a nice day.
> But what happens when those students want to work in a development background
Maybe start experimenting on their own instead of waiting someone to hold their hand and guide them in darkness?
> degrees do not mean much anymore here in UK
They don't mean much anyways unless they mean something to the student. Many students have the misconception that just by _passing_ the exams or _getting_ a degree will make them a good _XYZ_. One should seek clarity, experiment and enjoy ones work and one would never feel that their degrees / education don't mean anything.
The force is within you, let there be light. ;-)
This is because you are forgetting that whitespaces form a part of the DOM. The whitespace between your <a> and <p> elements (a newline in your case) forms a Text Node. To get hold of an element you would have to do something like this:
<!-- First.html -->
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>First</title>
<script type="text/javascript" src="Script.js"></script>
</head>
<body id="firstBdy">
<p class="verdana">First Paragraph</p>
<p class="verdana">Second Paragraph</p>
<a name="PAGE2"></a>
<p class="verdana" name="firstP">Six Paragraph</p>
<p class="verdana">Seven Paragraph</p>
<a name="PAGE3"></a>
<p class="verdana" name="verdanaP">Ten Paragraph</p>
<p class="verdana">Eleven Paragraph</p>
<br />
<a href = "#" onclick = "showAll(findP('a', 'PAGE'));">Click me</a>
</body>
</html>
/* Script.js */
/**
* @author sos
* @param {Node} rootElem The start point
* @param {String} pattern The name pattern to search for
* @returns The array of nextSiblings
* @type Array
* @see #findNextNode
*/
function findP(rootElem, pattern) {
var pList = [];
var aList = document.getElementsByTagName(rootElem);
for(var i = 0; i < aList.length; ++i) {
var e = aList[i];
if(e.name.indexOf(pattern) != -1) {
var nextP = findNextNode(e, 1 /* ELEMENT_NODE */);
if(nextP) {
pList[pList.length] = nextP;
}
}
}
return(pList);
}
/**
* Finds a node of the type <i>nodeType</i>
*
* @author sos
* @param {Number} nodeType
* @returns The node of type nodeType of null if not found.
* @type Node
*/
function findNextNode(root, nodeType) {
var e = root;
do {
e = e.nextSibling;
} while(e && e.nodeType != …
Netbeans and Eclipse are the two dominant free ones out there which I normally use.
> You either love them or you hate them
Bang on target.
I have seen people either worship those Head First books or avoid them like plague. The funny sketches found in all Head First books can be a good motivator or a complete turn off depending on your reading habits. Some people find it disturbing to find irrelevant images being presented before their eyes while some people think of it as a good means of learning a concept.
"The Java Programming Language" FTW!
> Just to be clear, the "Java" = J2SE right?
No, to be precise.
Java is a general purpose programming language. J2SE platform is a particular environment in which the Java programs run. All platforms have a VM(virtual machine) on which the programs run and a specialized API for that given platform.
> Men are a bunch of shallow jerks.
Can't live with, or without...
Here is a crude snippet:
<html>
<head>
<title>Forms</title>
<script type="text/javascript">
function objectify() {
var o = {};
var frms = document.forms;
/* loop through all the form objects */
for(var i = 0, maxI = frms.length; i < maxI; ++i) {
var frm = frms[i];
var elms = frm.elements;
var tmp = {};
/* loop through all the form elements of each form */
for(var j = 0, maxJ = elms.length; j < maxJ; ++j) {
var el = elms[j];
switch(el.type) {
case "textarea":
case "text":
tmp[el.name] = el.value;
break;
default:
/* add custom behavior for other form elements */
break;
}
}
o[frm.name] = tmp;
}
return(o);
}
</script>
</head>
<body id="bdy">
<form name="frmOne" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
<form name="frmTwo" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
<form name="frmThree" action="#">
<input name = "txtOne" value = "Text box one" />
<input name = "txtTwo" value = "Text box two" />
<input name = "txtThree" value = "Text box three" />
</form>
</body>
</html>
Just pass the object returned by objectify function to a function which returns the json string representation of a javascript object.
Can you link us to a sample page so we can find out what *exactly* are you trying to do?
You need to attach an event listener to the onkeypress event handler of the form element which would monitor the key strokes and submit the form as soon as a RETURN key is pressed.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>OK</title>
<script type="text/javascript">
function checkSubmit(e) {
e = e || window.event;
var code = e.keyCode || e.which;
if(code == 13 /* return key pressed */) {
var src = e.srcElement || e.target;
if(!!src && !!src.form)
src.form.submit();
}
}
</script>
</head>
<body id="bodyMain">
<form action="/action.do" method="get" onkeypress="checkSubmit(event);">
<select name="sel" multiple="multiple">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
<textarea name="txtArea"></textarea>
<input type="text" id="txtId" value="OK" />
<input type="text" name="txtName" value="txtName" />
<input type="button" value="Submit" />
</form>
</body>
</html>
No, it's not possible. Javascript just offers a client side scripting solution, nothing more. Employ a full blown server side programming language for this task.
A form is by default submitted when you press the return key. You need to show us how your form is structured so that we can offer more suggestions. Paste your code here with code tags.
> Am I right?
Yes, you can have nesting of arbitrary depths as long as it follows the key-value pair format where key is always a string and value can be either a string, number, array, another object, true, false or null.
> And how would I go about to access these values from codebehind? (ASP.NET)
Take a look at the .NET binding for JSON.
> Don't take it too seriously.
Just because that comment becomes part of a green or a red dot doesn't mean you shouldn't take it seriously. Had the same comment being written as a post, wouldn't that have looked bad? Wouldn't that have been violation of one of the laws of Daniweb? Yes, that sure would have been.
And as far as applying the bad word filter is concerned don't you think "Dude, what the fu** is a ****** like you doing in this forum? Just eat some sh** and get the f*** off." is very much capable of conveying the message? Just because someone doesn't give a damn doesn't mean that all of Daniweb members should adopt a thick skinned attitude.
By allowing such things to pass by in the form of reputation comments, you leave a big gaping hole in the entire system of 'Keep it pleasant'.
Or start giving warnings to those who do it.
First of all you should report the post in consideration so that the entire mod team have a look at it and decide whether it violates the site rules or not. With a lot of these things going around lately, I am sure there would be something definite coming out of this.
Again, with URL rewriting and redirection, those file extensions and URL's don't mean anything. I can very well have a page with url http://www.mysite.com/do.sos and serve a static page called index.html to the client.
> you dont actually see the page interacting with the javascript so it would technically be a html
> page
Every page served to the client technically has a content type of 'text/html'. The dynamic nature is due to the merit of the form element being able to post its data to a remote resource specified by it's action property, which is capable of processing that data.
Then the only option left would be to debug your script and see what exactly is causing the 'undefined' problem. A quick google search for IE debugging can give you some leads.
Hielo, please use code tags when posting code so that your code would be easily legible i.e. wrap your entire code in:
[code] /*your code here */ [/code]
OR
[code=javascript] /*your code here */ [/code]
> but i could have sworn ints were immutable (and so a 2D array of them also should be,
> right?).
The concept of immutability doesn't apply to primitives. Sure, the objects of all the wrapper classes for primitives are immutable, but the primitives themselves aren't and neither are arrays by default.
In your case, the array references gameboard, scratchboard and world all point to the same array object in heap. In case you want to preserve the original, clone the array instead of just assigning references.
Here is a crude example assuming that you are using the Logging API of Java and not some third party logging library.
public class Main {
private static Logger _log = Logger.getLogger(Main.class.toString());
public static void main(String[] args) throws Exception {
FileHandler handler = new FileHandler("c:/abcd", 512, 512);
handler.setFormatter(new SimpleFormatter());
_log.addHandler(handler);
LogManager manager = LogManager.getLogManager();
manager.addLogger(_log);
for (int i = 0; i < 128; ++i) {
_log.info("hello to all the people out there: " + i);
}
handler.close();
}
}
Here we use the FileHandler class instance to set the logger to write to the file system. It's constructor takes three parameters in our case: the path or the pattern with which you want to name your log files, the limit on the size of log files in bytes and the number of files to use when rotating.
From all the log files created, the file with the highest count will contain the most recent log information i.e. abcd1.log will contain the most recent log information.
Just fiddle around with the program and the API's and you would be just file.
> I typed a simple html program but the JavaScript is not running.
I guess that by 'not running' you mean a security alert which pops up at the top of the page saying it has blocked a script. If yes, then this is a common problem faced by users when running local scripts. Just click on that pop-up, select allow blocked scripts and you should be good to go.
There is also a way of permanently allowing blocked local scripts. I think this should help you out. If not, then post in the web browsers forum.
> If you know that then why you didn't give him the answer ?
Because there is none.
> try to give them a positive answer not to discourage ...
You should look for answers and not pleasing words.
You misread the requirements. The task is to change the background color of the selected text in a textarea and not the background color of the textarea.
◄ why vector is called synchronised?
Because it's methods are synchronized.
◄ why vector is synchronised?
A decision made by the language implementors.
Take a look at the source code of the Vector class and things will become a bit more clear for you. Just don't be attracted by the 'synchronized data structure' thing, hand craft your synchronization code. It would save you a lot of trouble.
> so can anybody help m,e how i can include so many files together in classpath
Use a build tool like Ant or Maven to ease this task. Using a build tool has become a d-facto standard for compiling / building / deploying your application and you should definitely go that way if you plan on surviving in a professional setting.
Build files are platform agnostic unlike shell scripts which are platform specific and can be run easily with minimalistic modifications. Google for 'Ant tutorial' to get started.
> This is my first Java course this is really frustrating
It would be better if you did a bit of research / reading before jumping right into coding. Just trying out various things at random wouldn't push you any close to attaining enlightenment.
Read your textbook, try to understand what the error message says, look at a sample declaration of a constructor and see what really makes your constructor different from a working one. Analyzing your problems and approaching them in a well planned manner would be much more beneficial.
Post the proper code along with the directory structure. element.style.backgroundImage = "url(my_image.jpg)";
should work assuming that the image is present in the same directory as the html file.
◄ S.O.S, why am i able to decode the encoded json string directly using eval without Douglas
◄ Crockfords' Javascript library for JSON. ?
This is because Crockford's library is not mandatory. It is more of a convenience library providing 'safe eval'. I hope you do realize that eval can execute any arbitrary piece of Javascript code. This is a major security issue if someone manages to inject a malicious script in your code. Crocford's library makes sure that doesn't happen by looking for malicious patterns.
Plus, how do you propose to encode Javascript objects and send them to your server in JSON. Converting Date objects to JSON format is a royal pain. I would recommend you to take a look at the Javascript library for JSON to understand it's full implications and the benefits it can bring.
> but both of the child windows the parent is same.
No, this isn't the case.
> when i open the first child window then the parent should be disable .when i close the first
> child window then the parent window should be enable
<!-- s.html -->
<html>
<head>
<title>s.html</title>
<SCRIPT >
my_window = null;
function popuponclick() {
my_window = window.open("p.html","myP", "status=1,width=750,height=450,resizable=no,modal");
}
function check() {
if(my_window && !my_window.closed)
my_window.focus();
}
window.onload = function() {
window.name = "s.html";
}
</script>
</head>
<body onclick="check();" onfocus="check();">
<p>
<a href="#" onclick="popuponclick();">show popup window</a>
<br />
<a href="#" onclick="window.close();">close popup window</a>
</p>
</body>
</html>
<!-- p.html -->
<html>
<head>
<title>p.html</title>
<script language = javascript>
my_window = null;
function popuponclick()
{
my_window = window.open("w.html","myW", "status=1,width=750,height=450,resizable=no,modal");
}
function check()
{
if(my_window && !my_window.closed)
my_window.focus();
}
window.onload = function() {
window.name = "p.html";
alert("Parent of p.html: " + opener.name);
}
</script>
</head>
<body onclick="check();" onfocus="check();">
<p>
<a href="#" onclick="popuponclick();">show popup window</a>
<br />
<a href="#" onclick="window.close();">close popup window</a>
</p>
</body>
</html>
<!-- w.html -->
<html>
<head>
<title>w.html</title>
</head>
<script type="text/javascript">
window.onload = function() {
alert("Parent of w.html: " + opener.name);
}
</script>
<body>
<p>
<a href="#">show popup window</a>
<br />
<a href="#" onclick="window.close();">close popup window</a>
</p>
</body>
</html>
Though the above code works, it has some major problems.
◄ All the above files have a DOCTYPE declaration missing which is a bad thing causing the browser to go in quirks mode.
◄ Instead of directly attaching event listeners …
> How is that insanity?
> I don't get it either.
You guys post in the 'Insanity' thread and expect it to make sense, that's just plain "insane". :-)
Please don't post "spam" or "Thank you" posts in this thread since this is meant to be used as a guide for all beginners and I am sure we would like it to be on topic. I hope you understand this.
» Introduction to Java «
To start off, Java is a general purpose programming language liked by application developers and web developers alike. It is the force which drives a large number of enterprise applications out there. Read more about it here. And yes, just for the records, Java is not slow!! [ 1 , 2 , 3 ] ;-)
» Getting started «
All you require to develop Java application is a text editor and a JDK which encompasses a Java compiler, a Java Virtual Machine and a host of tools which ease your development. Some handy links (ignore the specifications for the time being):
» Java 8 Download
» Java 8 online documentation
» Java 8 Language Specification
» Java 8 Virtual Machine Specification
After installing the JDK, you might want to take a look at the common problems beginners face when setting up Java and their solutions.
As a beginner, you should know the commonly used JDK development tools like javac, java, jar, javadoc to name a few. Read about them here.
There are a lot of IDE (Integrated Development Environments) …
Someone's in deep deep trouble. ;-)
> Maybe we should take this to the next level and start optimizing this in assembly?
It has got nothing to do with assembly. What he proposed / pointed out was a valid point.
> I honestly (for the teacher) hope it's not supposed to be in English...
It's not. It's Hindi.
I pity the teacher.
Read this.
As far as your problem is concerned, document.data_entry.topic.options(document.data_entry.topic.selectedIndex).text;
should be document.data_entry.topic.options[document.data_entry.topic.selectedIndex].value
;
The above way of referencing form elements is pretty inefficient and partly incorrect which is what the tutorial I posted aims at explaining.
It is working for me which means you are doing something wrong. Post the updated code with code tags. Read the announcements and site rules to know about them without which getting help might be a bit difficult.
What do you mean by 'not working'? We have no idea what you are trying to exactly achieve here? Are you testing this application in Firefox? If no, then you should start using it. If yes, then look at the error console.
From what I can see, you are accessing the elements of a form named 'userdetails' but I don't see that name given to your form element. Other than that, you need to provide us more details.
Next time post the code with code tags as mentioned in the announcements and site rules.
Solved. ;-)
> This is a not as messy solution
Your solution doesn't address the two things asked in your assignment. For one "Use a sentinel value to signal the end of input." and "After two chances, quit reading input".
You need to reset the tries counter after the user recovers from his mistake so he can get three consecutive attempts to enter a bad value. And what happens if he wants to just *stop*? You leave him no choice but to enter some junk characters three times in a row. This is one of the reasons why you were asked to keep a sentinel controlled loop.
Something simple like this would have done the job:
public class Test
{
public static void main(String[] args)
{
int tries = 0;
boolean isNormalTermination = true;
final int LIMIT = 3;
final float SENTINEL = -1.0f, TOLERANCE = 1e-6f;
float val = TOLERANCE, total = 0f;
Scanner in = new Scanner(System.in);
do
{
try
{
System.out.print("Enter a float value: ");
val = in.nextFloat();
total += val;
tries = 0;
}
catch(InputMismatchException e)
{
in.skip("\\w+"); //gobble up the junk characters
++tries;
if(tries == LIMIT)
{
isNormalTermination = false;
break;
}
System.out.println("Error! Please try again.");
}
}while(TOLERANCE < (Math.abs(val - SENTINEL)));
in.close();
if(!isNormalTermination)
{
System.out.println("You have exceeded " + LIMIT + " tries. Sorry");
}
System.out.print("Total: " + (total - SENTINEL));
}
}
Attach a function to the onclick and onfocus event handlers which would do something like this:
function focusChild()
{
if(my_window)
my_window.focus();
}
Here my_window is a global variable which holds the reference to the newly created popup window. It follows that as long as the child window is alive it will the one given focus.