Jump to content

How to echo the 'selected' value without using the submit button


rick001

Recommended Posts

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

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>

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 :)

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>';
      } 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.