Welcome Guest, Not a member yet? Register   Sign In
how to put javascript??
#1

[eluser]husni[/eluser]
hello..!
i am beginner in using php framework..
how to put javascript in php framework??
where can i put the javascript code??and how to call the code??
using framework,i am confuse a little bit about the directory..anyone can help me with very simple example..?
#2

[eluser]theprodigy[/eluser]
you put your javascript code as you normally would, in an external javascript file.
The file would then be put where you would normally put it (something like public_html/javascript/file.js)
Then you would call your javascript file the same way, but you put the call in whatever view you use for your header or template.

header.php (view)
Code:
<html>
<head>
<title><?php echo $title; ?></title>
<script src="/javascript/file.js" type="text/javascript"></script> //This is the call to your javascript file
</head>
<body>
#3

[eluser]haydenk[/eluser]
There's several ways of accomplishing this, javascript is a client-side language so it has to be loaded with the HTML markup.

If you've just loaded up the CI framework, look under "system/application/views/welcome_message.php", just as theprodigy pointed out, you insert into your HTML markup just the same as if you were not using CI or PHP.
#4

[eluser]husni[/eluser]
while using non php framework..i am used to call the name of the function of javascript codes..so in CI do i need to call the function as well??
Code:
function test()
{ something }

so i just call test(); or any other ways?
#5

[eluser]husni[/eluser]
[quote author="theprodigy" date="1267406031"]you put your javascript code as you normally would, in an external javascript file.
The file would then be put where you would normally put it (something like public_html/javascript/file.js)
Then you would call your javascript file the same way, but you put the call in whatever view you use for your header or template.

header.php (view)
Code:
<html>
<head>
<title><?php echo $title; ?></title>
<script src="/javascript/file.js" type="text/javascript"></script> //This is the call to your javascript file
</head>
<body>
[/quote]

this is my file.js code
Code:
function peringatan()
{
    alert('Hello hehe');    
}// JavaScript Document

it doesn't work at all..
maybe my .js code is wrong and the directory of my javascript file is wrong..
#6

[eluser]husni[/eluser]
[quote author="haydenk" date="1267406234"]There's several ways of accomplishing this, javascript is a client-side language so it has to be loaded with the HTML markup.

If you've just loaded up the CI framework, look under "system/application/views/welcome_message.php", just as theprodigy pointed out, you insert into your HTML markup just the same as if you were not using CI or PHP.[/quote]

i have put theprodigy code to my "system/application/views/welcome_message.php" but it doesn't work..
#7

[eluser]maria clara[/eluser]
hi husni,

im using a template for the header, body and the footer of my page. so i have put my header.php in system/application/view/template folder. and i use the <?base_url()?> in the src"". here's an example how i put it in the <head></head>


Code:
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.autocomplete.js">
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.i18n.js">
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.livequery.js">
type="text/javascript" src="<?=base_url()?>lib/flexigrid/flexigrid.js">
type="text/javascript" src="<?=base_url()?>lib/language/<?=$this->session->userdata('lang_select')?>.js">
type="text/javascript" src="<?=base_url()?>lib/site/common.js">
type="text/javascript" src="<?=base_url()?>lib/site/forms.js">



hope this can help you.

regards,
kahtrina
#8

[eluser]husni[/eluser]
[quote author="maria clara" date="1267514581"]hi husni,

im using a template for the header, body and the footer of my page. so i have put my header.php in system/application/view/template folder. and i use the <?base_url()?> in the src"". here's an example how i put it in the <head></head>


Code:
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.autocomplete.js">
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.i18n.js">
type="text/javascript" src="<?=base_url()?>lib/jquery/jquery.livequery.js">
type="text/javascript" src="<?=base_url()?>lib/flexigrid/flexigrid.js">
type="text/javascript" src="<?=base_url()?>lib/language/<?=$this->session->userdata('lang_select')?>.js">
type="text/javascript" src="<?=base_url()?>lib/site/common.js">
type="text/javascript" src="<?=base_url()?>lib/site/forms.js">



hope this can help you.

regards,
kahtrina[/quote]

when i create the function in the .js file..how to call the function in my view file when i have specified the src??
this is my first try to use js..so i am just trying to put the alert javascript..
#9

[eluser]husni[/eluser]
Code:
[removed][removed]

i have the function named
Code:
function peringatan()
{ alert('Hello Hello'); }

how to call the function name in my view file?
#10

[eluser]maria clara[/eluser]
i have a script.js file in my view. i have put it here view/js/(js file im calling). then im calling it in my controller like this:

Code:
function js()
    {
        $this->load->view('js/script.js');
    }

after calling, my js file was being loaded already. i have a module ex. user then inside the modules/user folder there are the folders for my controller, model and view.

so this is the structure for you to see.
Quote:
+system
+application
+modules <------ inside this modules are folders of diff. tables
+user
-controller
-model
+view
-js <---- where i put my .js file
+client
-controller
-model
+view
-js <---- where i put my .js file




Theme © iAndrew 2016 - Forum software by © MyBB