7 Replies - 374 Views - Last Post: 30 January 2012 - 12:34 PM

#1 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

function not getting called

Posted 29 January 2012 - 02:09 PM

hi my send() function is simply not getting called...please help

this is my javascript section
 <script type='text/javascript'>
        function store(x,y,z) { 			
var date = x+" "+y+" "+z;
document.getElementById("date").value=date;
			

        }
		function send(){
			
		var events=document.getElementById("event").value;
	location.href="q.php?day=" + x + "&month=" + y + "&year=" + z;
		
		}

    </script>

this is my html part(button)
 <input type="button" value="Click me!" onclick="send()" />


Is This A Good Question/Topic? 0
  • +

Replies To: function not getting called

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 3872
  • View blog
  • Posts: 11,405
  • Joined: 18-April 07

Re: function not getting called

Posted 29 January 2012 - 02:43 PM

You realize that you are using the variables "x","y" and "z" in the function store(). They are local to that function only. They are not seen in send(). Thus that line is going to error out saying that x,y,z are not defined. Unless of course you have x,y z also defined globally. But I doubt that is the case here.

:)

This post has been edited by Martyr2: 29 January 2012 - 02:44 PM

Was This Post Helpful? 3
  • +
  • -

#3 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Re: function not getting called

Posted 29 January 2012 - 03:16 PM

View PostMartyr2, on 29 January 2012 - 02:43 PM, said:

You realize that you are using the variables "x","y" and "z" in the function store(). They are local to that function only. They are not seen in send(). Thus that line is going to error out saying that x,y,z are not defined. Unless of course you have x,y z also defined globally. But I doubt that is the case here.

:)

hey i have modified the script so that the variables become global...still it isnt working
<script type='text/javascript'>
	var myObj = {};
        myObj.store = function store(x,y,z) { 			
var date = x+" "+y+" "+z;

document.getElementById("date").value=date;
myObj.p = x;
myObj.q = y;
myObj.r = z;			

        }
		
		
		
		myObj.send = function send(){
			
		var events=document.getElementById("event").value;
location.href="q.php?day=" + p + "&month=" + q + "&year=" + r;		
		}

    </script>


Was This Post Helpful? 0
  • +
  • -

#4 thrca  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 28
  • View blog
  • Posts: 65
  • Joined: 21-January 12

Re: function not getting called

Posted 30 January 2012 - 10:02 AM

You are not ever calling the store() function, thus, even though you have defined your x,y,z in the global scope, they are still empty.
Was This Post Helpful? 1
  • +
  • -

#5 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: function not getting called

Posted 30 January 2012 - 11:58 AM

Hi,

Your syntax is a bit off. For what you want to do you would use the syntax
 object.methodName = function(){//function definition here}



You also want to use the this keyword when you are inside method definitions and are assigning a value to an object's property. Something like this:
<script type='text/javascript'>
	var myObj = {};
	myObj.store = function(x,y,z) { 			
		var date = x+" "+y+" "+z;
		document.getElementById("date").value=date;
		//you are assigning properties to your object, use this keyword
		this.p = x;
		this.q = y;
		this.r = z;			
	}
	
	myObj.send = function(){
		var events=document.getElementById("event").value;
		location.href="q.php?day=" + this.p + "&month=" + this.q + "&year=" + this.r;		
	}
	//calling the methods
	myObj.store(3,4,5);
	myObj.send();
</script>



You also declare the variable "events" inside your send method but you don't do anything with it.
Was This Post Helpful? 0
  • +
  • -

#6 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Re: function not getting called

Posted 30 January 2012 - 12:00 PM

its ok guys i figured it out myself...thanks for the help anyways...appreciate it! :)
Was This Post Helpful? 0
  • +
  • -

#7 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: function not getting called

Posted 30 January 2012 - 12:32 PM

Hi,

When you find a solution to a problem you are posting about could you post your solution? This could help people searching for a solution to a similar problem :)
Was This Post Helpful? 0
  • +
  • -

#8 parthmody90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 24-January 12

Re: function not getting called

Posted 30 January 2012 - 12:34 PM

View PostJstall, on 30 January 2012 - 12:32 PM, said:

Hi,

When you find a solution to a problem you are posting about could you post your solution? This could help people searching for a solution to a similar problem :)

sure definitely!heres the solution guys:
 <script type='text/javascript'>
	
   var xx, yy, zz; //These are your global variables
   function store(x,y,z) {   
      xx = x;
      yy = y;
      zz = z;          
      var date = x+" "+y+" "+z;
      document.getElementById("date").value=date;
   }

   function send(){
      var events=document.getElementById("event").value;
      location.href="q.php?day=" + xx + "&month=" + yy + "&year=" + zz;      
   }
</script>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1