pfkdesign Posted August 14, 2008 Share Posted August 14, 2008 hi, i just wondering how can i use php in js. i have the flowing javascript code to add dynamic row, but i have an array in this js (HeatSelectOption[]) to get the label from php . here is the step.js . function addRowToTable() { var tbl = document.getElementById('tblheat'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow-4; var row = tbl.insertRow(lastRow); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode(iteration); cellLeft.appendChild(textNode); // select cell var cellRightSel = row.insertCell(1); var sel = document.createElement('select'); sel.name = 'steptype_'+ iteration; sel.id = 'steptype_'+ iteration; sel.options[0] = new Option(HeatSelectOption[0], '1'); sel.options[1] = new Option(HeatSelectOption[1], '2'); cellRightSel.appendChild(sel); // right cell var cellRight = row.insertCell(2); var el = document.createElement('input'); el.type = 'text'; el.name = 'textfield1_'+ iteration; el.id = 'textfield1_'+ iteration; el.size = 10; } and the array on the page is: <script> HeatSelectOption = new Array(); HeatSelectOption[0] = "<?php echo $selectOption['first_label'];?>"; HeatSelectOption[1] = "<?php echo $selectOption['second_label']; ?>"; </script> any idea ? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/119708-php-and-javascript-array/ Share on other sites More sharing options...
pfkdesign Posted August 14, 2008 Author Share Posted August 14, 2008 ??? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/119708-php-and-javascript-array/#findComment-616797 Share on other sites More sharing options...
pfkdesign Posted August 14, 2008 Author Share Posted August 14, 2008 any idea ? !!!!!! nobody knows ?!!! ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/119708-php-and-javascript-array/#findComment-616902 Share on other sites More sharing options...
kenrbnsn Posted August 14, 2008 Share Posted August 14, 2008 That should work fine. Are you having a problem with it? Just remember that PHP gets executed and stops before Javascript sees any code. If you need this to be dynamic, you would need to use AJAX. Don't bump your post so quickly. Ken Quote Link to comment https://forums.phpfreaks.com/topic/119708-php-and-javascript-array/#findComment-616941 Share on other sites More sharing options...
pfkdesign Posted August 14, 2008 Author Share Posted August 14, 2008 hi , unfortunately it is not working,i used ajax ( customized code js and php code ) , and i can not understand why it is not working ?! ??? i'm adding dynamically a row by pressing (+) or removing by pressing (-) (a dropdown menu and a text field) and inserting into the database, it is working when i use static label. so it should be a problem to use php with js , the javascript executed first and pass blank label (it is not let to execute php) !! thats why it is return blank label for dropdown menu! any idea? Quote Link to comment https://forums.phpfreaks.com/topic/119708-php-and-javascript-array/#findComment-616961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.