rick001 Posted January 5, 2012 Share Posted January 5, 2012 here is the code <label for="rank">Font</label> <select class="element select medium" id="fonts" onchange="<?php echo 'selected'; ?>" name="fonts"> <option value="Arial" selected="selected">Arial</option> <option value="times" selected="selected">Times New Roman</option> </select> It is supposed to echo the value selected but it does nothing any ideas regarding what i should do? Also what i really want to do is create a cookie which will contain the selected value and then use this value of the cookie later. But I cant even manage to echo the values so thought it would be better to first learn how to echo and then try to create a cookie out of it Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/ Share on other sites More sharing options...
trq Posted January 5, 2012 Share Posted January 5, 2012 onChange is a client side event, PHP executes on the server. Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304412 Share on other sites More sharing options...
rick001 Posted January 5, 2012 Author Share Posted January 5, 2012 onChange is a client side event, PHP executes on the server. what do u suggest i do to achieve the result i want really running out of ideas so ne suggestion would be welcome Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304417 Share on other sites More sharing options...
charles07 Posted January 5, 2012 Share Posted January 5, 2012 rick001 why do u want to use php here. just use simple javascript <label for="rank">Font</label> <select class="element select medium" id="fonts" onchange="findmyvalue()" name="fonts"> <option value="Arial" selected="selected">Arial</option> <option value="times" selected="selected">Times New Roman</option> </select> <script type="text/javascript"> function findmyvalue() { var myval = document.getElementById("fonts").value; alert(myval); } </script> Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304426 Share on other sites More sharing options...
rick001 Posted January 5, 2012 Author Share Posted January 5, 2012 rick001 why do u want to use php here. just use simple javascript <label for="rank">Font</label> <select class="element select medium" id="fonts" onchange="findmyvalue()" name="fonts"> <option value="Arial" selected="selected">Arial</option> <option value="times" selected="selected">Times New Roman</option> </select> <script type="text/javascript"> function findmyvalue() { var myval = document.getElementById("fonts").value; alert(myval); } </script> Thanks for the help worked just fine, and i dont know much abt javascript so the trouble trying to use php which i am somewhat well versed in thank though its working fine Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304455 Share on other sites More sharing options...
trq Posted January 5, 2012 Share Posted January 5, 2012 Somewhat well versed in? Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304461 Share on other sites More sharing options...
rick001 Posted January 5, 2012 Author Share Posted January 5, 2012 Somewhat well versed in? opps sorry typo; well versed in php just love it by the way i am working on that code and everything was going fine until i discovered i would need another function thats in a diff page to be called everytime that select value gets as well as creating a cookie so here is what i did didnt test it out yet let me know if u think it has faults <div id ="pfc_fonts_select" class="pfc_dropdown"> <label for="Font">Select Font </label> <select class="element select medium" id="fonts" onchange="findmyvalue()" name="fonts"> <option value="arial" selected="selected">Arial</option> <option value="algerian" selected="selected">Algerian font</option> <option value="bookman" selected="selected">Bookman</option> <option value="braggadocio" selected="selected">Braggadocio</option> <option value="courier" selected="selected">Courier</option> <option value="desdemona" selected="selected">Desdemona</option> <option value="garamond" selected="selected">Garamond</option> <option value="modern" selected="selected">Modern</option> <option value="verdana" selected="selected">Verdana</option> </select> <script type="text/javascript"> function findmyvalue() { var myval = document.getElementById("fonts").value; document.cookie ='font=myval; expires=Thu, 2 Aug 3001 20:47:11 UTC; path=/'; } pfc.changeFont(); </script> </div> the function changeFont is in another page and here is what it looks like // Set Font for the text changeFont: function() { fcookie = getCookie('font'); var wval = '<font ' + 'face' + '=' + fcookie + '>' + wval + '</font>'; } Link to comment https://forums.phpfreaks.com/topic/254391-how-to-echo-the-selected-value-without-using-the-submit-button/#findComment-1304476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.