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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.