echo JavaScript inside PHP -
this question has answer here:
i using following code change button when clicked echoing javascript's document.getelemenbyid
property button remains is:
while($result=mysql_fetch_array($result1)) { $i=1; echo " <tr> <form action='student.php' method='post'> <td>$result[0]<input type=\"hidden\" name=\"company\" value=\"$result[0]\"></td> <td> <input type=\"checkbox\" name=\"yes\" /> <input type=\"submit\" name=\"apply$i\" id=\"apply$i\" class=\"buttons\" style=\"border: none\" value=\"apply now!\" onclick=\"return confirm('are sure want apply?');\"> <input type=\"hidden\" name=\"apply$i\" value=\"apply$i\"> </td> </form> </tr> <tr><td><input type=\"text\" id=\"ankur\"></td></tr> "; $i++; } echo "</table></center>";
here button id apply$i
should change applied
string per following code
$id=$_session['sessionid']; if(isset($_post['apply1'])) { if(isset($_post['yes'])) { $yes=trim(mysql_prep($_post['yes'])); $company=trim(mysql_prep($_post['company'])); $button_id=trim(mysql_prep($_post['apply1'])); if($yes=="on") { $query ="select `branch`,`class` `student_details` `userid`='$id'"; $temp1= mysql_query($query); $temp2= mysql_fetch_array($temp1); $query="insert `student_applied` values ('$id' ,'$temp2[0]' ,'$temp2[1]' ,'$company')"; //$query="update `student`.`users` set `activated` = '1' `users`.`userid` = '$student'"; $result = mysql_query($query); confirm_query($result); if($result) { echo "ok"; echo "<script language='javascript' type='text/javascript'>document.getelementbyid('apply1').innerhtml ='applied';</script>"
does know reason?plz help
instead of settingg $i inside loop, should set outside , increment value, like
$i=1; while($result=mysql_fetch_array($result1)){ //your rest of code output content $i++; }
that way have different id each button, , javascript should work you.
Comments
Post a Comment