简体   繁体   中英

Send data with button from php to java script

Hi i want to send data from php code to java script and java script 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 java script 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 java script java script code

function sendToEdit(pID,phID,thDate,type) 

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' .

<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 ?>');"  />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM