Skip to main content

Thread: how to pass values in javascript?


i can call function <body> in javascript, can pass values function? check this.....
php code:
<html>
<
head>
<
title>
mul table
</title>
</
head>

<
script language="javascript">

function 
abhimul() {
var 
abhi=prompt("enter a number");
document.write("you entered " +abhi"<br>");
    
for(var 
i=1i<=10i++)
{
    
document.write(abhi +" * " "=" +(i*abhi)+ "<br>");
}

}
</script>

<body>
<a href="javascript:abhimul()">know tables</a>
</body>

</html> 
if want send values, tried din't work....
php code:
<body>
var 
abhi=prompt("enter a number");
document.write("you entered " +abhi"<br>");
abhimul(abhi);
</
body
in called function, can recieve abhimul(var abhi) ?
how pass values?

you try use javascript without script tags in body of html page. not going work.
example guess want user enter number , let javascript use given number.

javascript functions can have parameters so:
code:
<script type="text/javascript">  function test(param1, param2)  {    alert( param1 +' '+ param2 );  }  </script>
now can call javascript function way did in first example, 2 parameters.
result in alert message "test param1 test param2'
code:
<a href="javascript:test('test param1', 'test param2')">link</a>
so guess want:
code:
<script type="text/javascript">  function asknumber()  {    var number = prompt("enter number");    alertnumber( number );  }    function alertnumber( number )  {    alert( number );  }  </script>
then html body create link calling "asknumber" function same way did in first example.

more on javascript function: http://www.w3schools.com/js/js_functions.asp


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] how to pass values in javascript?


Ubuntu

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support