Thread: Not Working !

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    Question Not Working !


    html file !
    Code:
    <form id="form" method="post">
    <input type="text" id="tasks" required>
    <br><br>
    
    <input type="submit" id="submit" value="Add A Task">
    
    <div id="output"></div>
    </form>
    JS file !

    Code:
    var tasks = [];
    	 
    function calculate(){
    	'use strict'
    	 var tasks = document.getElementById('task');
    	 var output = document.getElementById('output');
    	 var message = '';
    	 if (tasks.value)
    	 {
    		 task[tasks.length] = tasks;
    		 		 };
    			message = 'You have ' + tasks.length + ' task(s) in you to-do list.';
    						
    			if(output.textContent !== undefined){
    				output.textContent = numbers;
    				}else{
    					output.innerText = numbers;
    					};
    				return false;
    
    function init()
    {
    	'use stric';
    	var form =	document.getElementById('form');
    	form.onsubmit = calculate;
    		};
    		window.onload = calculate;
    };

    i dont know why it is not working
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    With 68 posts you should already 1) have read the sticky posts and 2) know that "it doesn't work" is not enough information.

    Take a look at the pairs of { and }.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    ?


    If i have to check then why i should post here !
    Thanks for reply

    Comments on this post

    • Jacques1 disagrees : Stop wasting our time.
  6. #4
  7. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    ionezation, that is the funniest thing I have read in a while ...
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,663
    Rep Power
    1958
    Originally Posted by ionezation
    If i have to check then why i should post here !
    Thanks for reply
    No worry (that I will force you to do something); can tell I, for example, just post for fun anyway.
    Thanks for feedback.


    @badger_fruit: can something be fun in a "sad-kinda-way"?
  10. #6
  11. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    yes :'(
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0
    badger_fruit - i am posting here because i am having an issue. Why would i post either if i dont have a problem.
    If my posts bother someone so i think i should left this forum and deactivate my account
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    There might be a tiny misunderstanding:

    “Helping someone” doesn't mean that you can sit back while we do your work. We expect you to turn your brain on, write down a proper error description and actively work on the issue.

    Every community expects this. If you think you can just dump a piece of code with the comment “Don't work!” and then wait for the solution, you won't be successful anywhere. Maybe people will tolerate this for a while, assuming you're only 12 and don't know any better. But they won't hold your hand forever.

    So either start writing posts which make sense. Or go find a personal assistent who's willing to fix your code for money.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0

    Sorry :)


    Alrite friends i accept what i did and apologize for it. But everytime i post here is just for the issue that need to be resolved not for fun. I am in my learning phase and you know when you are on your own, only few hands are there to help you. I am doing everything on my own from books tutorials etc. Basically i am preparing for MCSD [html5 css3 javascript] store application developer. Well no offense at all and chill dudes
  18. #10
  19. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Hello ionezation,
    I apologise if I caused offence.
    I do understand that you're here for help and the replies you've received are not helping at all but as Jaques1 said, we're not able to help if you just drop some random code here and shout "Not working!".

    As it is, as a gesture of goodwill, I will try my best to help you, I will take time away from my paid job (like most of the other posters on this form do too) to post some assistance here for free ....

    Your HTML file seems to be OK so I'll move onto the JS ...
    I will add comments in as I find things ....

    Code:
    var tasks = [];									// I presume you're declaring an array here, try this instead:
    											//	var tasks = new Array();
    
    function calculate(){
    	'use strict'									// No trailing semi-colon ( ; )
    	 var tasks = document.getElementById('task');
    	 var output = document.getElementById('output');
    	 var message = '';
    	 if (tasks.value)
    	 {
    		 task[tasks.length] = tasks;
    	 };										// No need to have a semi-colon at the end here
    
    	message = 'You have ' + tasks.length + ' task(s) in you to-do list.';
    						
    	if(output.textContent !== undefined){
    		output.textContent = numbers;
    	}else{
    		output.innerText = numbers;
    	};										// No need to have a semi-colon at the end here
    	return false;
    
    // There is no closing brace for your "calculate" function
    
    
    function init()
    {
    	'use stric';									// mis-spelling of 'strict'
    	var form =	document.getElementById('form');
    	form.onsubmit = calculate;						// If you're calling a function, you need to append ()
    											// Example:  calculate();
    
    	};										// No need for the ending semi-colon here
    
    window.onload = calculate;					// As above: missing ()
    };									// Why the extra closing brace and semi-colon?
    									// is this misplaced from your calculate function perhaps?

    Of course, you do realise that as soon as the user navigates away from the page or presses F5 to refresh the page, the tasks array will be wiped? To store the data you're going to need to write it into either a file (bad bad bad) or a database of some description. However, given where you're struggling now, that's going to be a post/subject for another day

    Anyway, those are all things that I see are wrong, the comments above will hopefully help you to get working code though.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    876
    Rep Power
    275
    I see that nobody has yet caught this?

    Code:
    <input type="text" id="tasks" required>
    
    
    var tasks = document.getElementById('task');
    you have an ID of "tasks" in your HTML form, but you are trying to target an ID of "task" in your Javascript.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0
    Code:
    var tasks=[];	 
    function calculate(){
    	'use strict';
    	var tasks = document.getElementById('tasks');
    	 var output = document.getElementById('output');
    	 var message = '';
    	 if (task.value)
    	 {
    		 tasks[tasks.length] = task;
    		 		 
    			message = 'You have ' + tasks.length + ' task(s) in you to-do list.';
    						
    			if (output.textContent !== undefined){
    					output.textContent = numbers;
    						} else
    							{
    							output.innerText = numbers;
    							}
    		return false;
    	 }
    }
    
    
    
    	 
    function init()
    {
    	'use strict';
    	var form =	document.getElementById('form');
    	form.onsubmit = calculate();
    		};  // end init()
    		
    		window.onload = calculate;

    Thanks for reply mates ... well its ok dont need to worry about its ok ... everything is fine no argue at all. Well with all corrections you provided it is still not working
  24. #13
  25. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    i think that you're going to have to add a few alert("something"); along the code to see where it gets to so then you can determine what's actually going wrong ....

    Code:
    var tasks= new Array();	 
    
    function calculate() {
    	alert ("calculate start");
    	var tasks = document.getElementById('tasks');
    	var output = document.getElementById('output');
    	var message = '';
    
    	alert ("Variables set");
    	if (task.value) {                         // Should this be tasks.value (note the "s")?
    		alert ("There's a value");
    		tasks[tasks.length] = task;
    		message = 'You have ' + tasks.length + ' task(s) in you to-do list.';
    		alert("The message is: " + message );
    		if (output.textContent !== undefined) {
    			output.textContent = numbers;
    		} else {
    			output.innerText = numbers;
    		}
    		return false;
    	} else {
    		alert ("There is no value");
    	}
    	alert ("calculate ending");
    }
    function init() {
    	alert ("init start");
    	'use strict';
    	var form =	document.getElementById('form');
    	form.onsubmit = calculate();
    	alert ("init ending");
    }
    
    window.onload = calculate;

    I've added debugging into the code (the "alert" statements) as well as sorted the indentation out and added an "else" in the calculate function which, if there is no .value, will at least alert you to that fact. You should be able to use those debugging points to figure out where the script is stopping. For example, if you get the alert "calculate start" but not "variables set", you know it's somewhere between those two alerts.

    Good luck!
    Last edited by badger_fruit; January 14th, 2014 at 02:43 PM.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    100
    Rep Power
    0
    alrite let me check it

IMN logo majestic logo threadwatch logo seochat tools logo