хотела бы узнать все возможности связи между javascript и php,
вот такой код:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//mail_form.inc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style>
.one{ background-color:#ffeeef;
font-family:Arial;
font-size: 100%;
font-weight: bold;
color:#112383;
</style>
<script>
var store=new Array();
var storeindex=new Array();
//groupe 1 for Julio Iglesias
store[0]="pay";
store[1]="man";
storeindex[0]=1;
storeindex[1]=1;
//groop2 for Tracy Chapman
store[2]="america";
store[3]="last";
storeindex[2]=2;
storeindex[3]=2;
//groop3 for Brayan Adams
store[4]="dog";
store[5]="california";
storeindex[4]=3;
storeindex[5]=3;
function listsongs(n_this,n_form_songs,n_store,n_storeindex)
{
var i,new_elem;
var temp;
for(i=n_form_songs.options.length;i>=0;i--)
n_form_songs.options=null;
for ( x = 0 ; x < store.length ; x++ )
{
if ( storeindex[x] == n_this.value )
{
new_elem = document.createElement('option') ;
new_elem.setAttribute('value',x);
var txt = document.createTextNode(store[x]);
new_elem.appendChild(txt);
n_form_songs.appendChild(new_elem);
}
}
}
</script>
</head>
<body bgcolor="#fffeee">
<form name="myform" method="post" action="php_form.php">
<table height="100%" width="50%" border="0" align="center" class="one">
<tr>
<td colspan="2" align="center">blabla...
<hr>
</td>
</tr>
<tr>
<td>Name
<input type="text" name="name" >
</td>
<td align="right">Family
<input type="text" name="family" >
</td>
</tr>
<tr>
<td>Email
<input type="text" name="mail" >
</td>
<td >Country
<select id="country" >
<option>Israel</option>
<option>USA</option>
</td>
</tr>
<tr>
<td >Singer
<select id="sing" name="sings" onchange="temp=listsongs(this,myform.songs,store,storeindex)">
<option value="0" >SELECT</option>
<option value="1" >Julio Iglesias</option>
<option value="2">Tracy Chapman</option>
<option value="3">Brayan Adams</option>
</select>
</td>
<td >Singer
<select id="songs" name="songs" >
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="sub" value="submitt">
</td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//php_form.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
$submit=1;
if(!$name)
{
$submit=0;
$name="<b>invalid name</b>";
}
if(!$mail)
{
$submit=0;
$mail="<b>invalid email addres</b>";
}
echo
(
"<b>You have submitted following:</b>"."<br>"."Name: $name"."<br>"."Email: $mail"
);
echo("<br>"."Singer:");
switch($sings)
{
case "0":
$resultName="SELECT";
break;
case "1":
$resultName="Julio Iglesias";
break;
case "2":
$resultName="Tracy Chapman";
break;
case "3":
$resultName="Brayan Adams";
break;
}
echo "$resultName";
?>
<!-- --------------------------------------------- -->
</body>
</html>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
как я могу вызвать функцию javascript from php ,
и вообше,я не понимаю,если написать все в php, то зачем тогда javascript.
я хочу вывести на экран songs и незнаю как и как было бы правильней.
если есть много способов,буда рада узнать о них .
вот такой код:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//mail_form.inc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style>
.one{ background-color:#ffeeef;
font-family:Arial;
font-size: 100%;
font-weight: bold;
color:#112383;
</style>
<script>
var store=new Array();
var storeindex=new Array();
//groupe 1 for Julio Iglesias
store[0]="pay";
store[1]="man";
storeindex[0]=1;
storeindex[1]=1;
//groop2 for Tracy Chapman
store[2]="america";
store[3]="last";
storeindex[2]=2;
storeindex[3]=2;
//groop3 for Brayan Adams
store[4]="dog";
store[5]="california";
storeindex[4]=3;
storeindex[5]=3;
function listsongs(n_this,n_form_songs,n_store,n_storeindex)
{
var i,new_elem;
var temp;
for(i=n_form_songs.options.length;i>=0;i--)
n_form_songs.options=null;
for ( x = 0 ; x < store.length ; x++ )
{
if ( storeindex[x] == n_this.value )
{
new_elem = document.createElement('option') ;
new_elem.setAttribute('value',x);
var txt = document.createTextNode(store[x]);
new_elem.appendChild(txt);
n_form_songs.appendChild(new_elem);
}
}
}
</script>
</head>
<body bgcolor="#fffeee">
<form name="myform" method="post" action="php_form.php">
<table height="100%" width="50%" border="0" align="center" class="one">
<tr>
<td colspan="2" align="center">blabla...
<hr>
</td>
</tr>
<tr>
<td>Name
<input type="text" name="name" >
</td>
<td align="right">Family
<input type="text" name="family" >
</td>
</tr>
<tr>
<td>Email
<input type="text" name="mail" >
</td>
<td >Country
<select id="country" >
<option>Israel</option>
<option>USA</option>
</td>
</tr>
<tr>
<td >Singer
<select id="sing" name="sings" onchange="temp=listsongs(this,myform.songs,store,storeindex)">
<option value="0" >SELECT</option>
<option value="1" >Julio Iglesias</option>
<option value="2">Tracy Chapman</option>
<option value="3">Brayan Adams</option>
</select>
</td>
<td >Singer
<select id="songs" name="songs" >
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="sub" value="submitt">
</td>
</tr>
</table>
</form>
</body>
</html>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//php_form.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?
$submit=1;
if(!$name)
{
$submit=0;
$name="<b>invalid name</b>";
}
if(!$mail)
{
$submit=0;
$mail="<b>invalid email addres</b>";
}
echo
(
"<b>You have submitted following:</b>"."<br>"."Name: $name"."<br>"."Email: $mail"
);
echo("<br>"."Singer:");
switch($sings)
{
case "0":
$resultName="SELECT";
break;
case "1":
$resultName="Julio Iglesias";
break;
case "2":
$resultName="Tracy Chapman";
break;
case "3":
$resultName="Brayan Adams";
break;
}
echo "$resultName";
?>
<!-- --------------------------------------------- -->
</body>
</html>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
как я могу вызвать функцию javascript from php ,
и вообше,я не понимаю,если написать все в php, то зачем тогда javascript.
я хочу вывести на экран songs и незнаю как и как было бы правильней.
если есть много способов,буда рада узнать о них .