Click to See Complete Forum and Search --> : naming function incrementally


moccacinoe
06-25-2007, 10:11 AM
Hi,

i have a problem regarding mys javascript function.
i have several forms which name's like this:


for($i=0; $i<$period; $i++)
{
$queryCount= "select appId, appTypeName, appStatName from appointment where appId= '$appId'";
$result= safe_query($queryCount);
$num_rows = mysql_num_rows($result);
while (list($appId, $appTypeName, $appStatName)= mysql_fetch_array($result))
{
print "<form name= \"bookAppointmentc$appId\" id= \"bookAppointmentc$appId\" action= \"../action/bookAppointment.php\" method= \"GET\">";
print "<select name= \"appStatName\" class= \"onProgress\" onChange= \"return changeAppc$appId()\">\n";
.....
print "<a href= \"javascript: submitFormc$appId()\"> Changeaa </a> \n";
}
}


since i don't really good at javascript, i create the javascript func like this:

function bookAppointmentc1()
{
...
}

function bookAppointmentc2()
{
...
}

function submitFormc1()
{
...
}



and so on..
i know it's wrong, but i don't know how to make it right?
or is there any other way in creating the form name in php?

thank's for your attention

Fang
06-25-2007, 10:35 AM
I assume you require a generic function changeApp() , not bookAppointment() ?
In the PHPonchange="return changeApp(this);"
In JavaSscript:function changeApp(form) {
alert(form.id); // the form you have to deal with
}

moccacinoe
06-25-2007, 11:39 AM
Hi,

thank's a lot for your reply, i was mistype about the bookAppointmentc function, it should be changeApp() ...=)


onchange="return changeApp(this);"

function changeApp(form) {
alert(form.id); // the form you have to deal with
}

i've tried to do like you recommended, but it returns me "undefined"..
so, can i name the form id into something like this? --> <form id= "bookAppointmentc">
if i do it like that, then can the form.id uniquely identified the form id?
sory for asking a simple question.. but i still a newbie in js =)

regards,

moccacinoe

Fang
06-25-2007, 12:43 PM
Each form is given an unique id by the PHP code.