0

I simple want to wan to pass php string into java script function here is the code. I know there is problem in sending string to javascript function but how can i solve it????If i pass integer value then it works fine it shows problem in passing string

echo "<td><a id='".$row['Patient_Id']."' onclick=changename(".$row['Patient_Id'].",".$row['age'].",".$row['Notes'].") >".$row["Patient_Name"]."</a></td></tr>";

Here is the java script funtion

function changename(vlue,age,id)
{
 alert(id);
 var MyDiv1 = document.getElementById(vlue);
 document.getElementById('age').innerHTML=age;          
 var MyDiv2 = document.getElementById('pname');
 MyDiv2.innerHTML = MyDiv1.innerHTML;   //d     
 var MyDiv3 = document.getElementById('hidden');
 MyDiv3.value  =vlue;               
}
4
  • There shouldn't be a problem here if the echo worked correctly. Commented Feb 16, 2015 at 18:34
  • it works fine if i pass only integer value but problem is when i tried to pass strings Commented Feb 16, 2015 at 18:36
  • Look at the actual HTMl output of the table data - see anything weird there? Commented Feb 16, 2015 at 18:36
  • no every thing works fine expect this problem is there any other specific syntax about passing string i don't know it well :( Commented Feb 16, 2015 at 18:37

2 Answers 2

2

Your parameters are string values, so they should be enclosed in quotes:

echo "<td><a id='".$row['Patient_Id']."' onclick=changename( '".$row['Patient_Id']."' , '".$row['age']."' , '".$row['Notes']."' ) >".$row["Patient_Name"]."</a></td></tr>";
//                                                           ^----------------------^ etc

As it stands, JavaScript perceives your strings as identifiers. If you had checked your console you'd have seen corresponding errors (assuming these identifiers aren't defined).

Sign up to request clarification or add additional context in comments.

Comments

0

your onclick doesn't have quotations

echo "<td><a id='".$row['Patient_Id']."' onclick='changename(".$row['Patient_Id'].",".$row['age'].",".$row['Notes'].")' >".$row["Patient_Name"]."</a></td></tr>";
                                                 ^ //here                                                             ^ // and here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.