tokool420 Posted May 25, 2011 Share Posted May 25, 2011 Hello, I have below javascript, which I need to put in a new php page. However I need the vistiors to pass in the username to the script either by clicking the link for that user or by entering a value on the website. I am not sure how can I do this in php script and modify below java script to make it work. Any help will be greatly appreciated. <pre class="example"> $(function(){ $(".tweet").tweet({ join_text: "auto", username: "NEED_TO_BE_PARAMETER", avatar_size: 68, count: 25, auto_join_text_default: "said,", auto_join_text_ed: "I", auto_join_text_ing: "I wase", auto_join_text_reply: "I replied", auto_join_text_url: "I was checking out", loading_text: "loading..." }); }); </pre> <div class='query'></div> <script type="text/javascript"> $(function(){ $(".example").each(function(i, e){ eval($(e).text()); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/237393-javascript-parameter-passing-in-php-script/ Share on other sites More sharing options...
Fadion Posted May 25, 2011 Share Posted May 25, 2011 The simplest solution that come to mind is printing PHP directly to the Javascript code, but that wouldn't be very clever. I'm talking about something like below, where POST data is printed directly in the Javascript code. $(function(){ $(".tweet").tweet({ join_text: "auto", username: "<?php echo $_POST['username']; ?>", avatar_size: 68, count: 25, auto_join_text_default: "said,", auto_join_text_ed: "I", auto_join_text_ing: "I wase", auto_join_text_reply: "I replied", auto_join_text_url: "I was checking out", loading_text: "loading..." }); }); The best method would be using just Javascript and no PHP. You can make an input and a button, so when the user submits it, you catch that data with Javascript and pass it to the rest of the code you have. Something like: //js code $('button').click(function(){ var username = $('#username').val(); //this is the username }); //html code <input type="text" name="username" id="username" /> <button type="button">Submit</button> You'll need to provide alternate form submitting for non-javascript users, but as your functionality is based on Javascript, I guess you don't care. Quote Link to comment https://forums.phpfreaks.com/topic/237393-javascript-parameter-passing-in-php-script/#findComment-1219920 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.