-1

Hi i want to send data from php code to JavaScript and JavaScript code send themes to another php file like below:

<td>
  <input type="submit" value="Edit" name="edit" id="edit"    
     onclick="sendToEdit(
               <?php echo $row['pID']?>
              ,<?php echo $row['phID']?>
              ,<?php echo $testHistoryDate ?>
              ,<?php echo (string)$type ?>);"/>

when i debug with firebug i see php code make true values in the php area but when send themes to JavaScript can't send
<?php echo $testHistoryDate ?>,<?php echo (string)$type ?>);
true values and send another date for testHistoryDate and true value for (string)$type
but fire bug make below error:

Phibrinozhen is not defined
[Break On This Error]
sendToEdit(9004, 119002, 1997, Phibrinozhen);

in the above code 1997 isn't true value
true value is:

onclick="sendToEdit(9004,119002,2010-10-03,Phibrinozhen);"

that php make but JavaScript JavaScript code

function sendToEdit(pID,phID,thDate,type) 
1
  • Typical newbie mistake: wrongly believing that Java and JavaScript are the same language and writing JavaScript with 2 separate words... Commented Jun 27 at 22:45

2 Answers 2

3

The error is occurring because you trying to pass string literals without telling JavaScript they are strings. You need to escape at least your final two parameters with quotes: '2010-10-0', 'Phibrinozhen'.

2
<td><input type="submit" value="Edit" name="edit" id="edit" onclick="sendToEdit('<?php echo $row['pID'] ?>','<?php echo $row['phID']?>','<?php echo $testHistoryDate ?>','<?php echo (string)$type ?>');"  />

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.