Skip to content
WJunction - Webmaster Forum

Print selected value from list menu - PHP

Status
Not open for further replies.

NightLightW

Established Member
173
2011
23
Hello,

I want to do this. When you select from
2wqa00k.png
you select ex. Large and i want to be show here
16jhp2v.png


I don`t know how to print Large to location that i want. I don`t need data base for this? Thanks :)

here is my code
PHP:
<!DOCTYPE html>
<html>
    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
        function disp_text()
        {
        var w = document.myform.mylist.selectedIndex;
        var selected_text = document.myform.mylist.options[w].text;
        alert(selected_text);
        }

    </script>
    <style>
        .clear{clear: both;}   

        .lev
        {
        float: left;
        border: 1px solid ghostwhite;
        border-radius: 10px 10px 10px 10px;
        font-size: 10px;
        margin: 3px;
        padding: 10px;
        text-align: left;
        width: 308px;
        height:156px;
        }

        .ime{font-size:13px; font-weight:bold;}
        .info{color:grey}
    </style>
        <title></title>
    </head>
    <body>

    <div class="lev">
        <div style="float:left;margin: 0 5px 0 0;width: 105px; height: 100px">
        <img src="http://www.dominos.mk/gallery/395s.jpg"/></div>
        <div class="ime">  Маргарита  </div>
        <div class="info">пелат,кашкавал,маслиново масло</div>
        <div class="clear"></div>
        <div><select>
            <option>Small</option>
            <option>Medium</option>
            <option>Large</option>
        </select></div>
    </div>
    <!--<div id="desen">Desen div</div>-->


</body>
</html>
 

9 comments

Do you want to display the value of the SELECT on the same page right after changing it, or later on another page?

In the first case, you have to use JS. I recommend including jQuery in the HEAD part then doing something like
Code:
<script type="text=javascript">
$(document).ready(function() {
  $('[I]#yourselectid[/I]').change(function() {
    var selectval = $(this).val();
    $('[I]#targetelementid[/I]').text(selectval);
  });
});
</script>
If you want to display the value on another page, you'll have to make a proper form. Add a name property for your SELECT and value properties for the OPTIONs, put it in a FORM element, define its action and method properties, add a submit button, then create the landing page for the form. Once the values have been sent you can display with $_GET['yourselectname'] or $_POST['yourselectname'], or if you want to display the value on a different page, you can put it in a session variable or in a regular cookie.
 
Yes i want to display the value of the select on the same page right after changing.
with this JS will do that?
Code:
<script type="text=javascript"> $(document).ready(function() {   $('[I]#yourselectid[/I]').change(function() {     var selectval = $(this).val();     $('[I]#targetelementid[/I]').text(selectval);   }); }); </script>
 
This is okey. But when i make some changes in code like this JS don't work. Also if i put radio buttons dont work.Where can be problem?
Code:
http://jsfiddle.net/HonGCheN/UHnp7/
 
You don't need the <script> tags in the JS box, and you have to select jQuery from the drop down on the left side. Also, I have no idea of what you're trying to do with that.
 
idea is when you select 320$ or 200$ from list, to show that immediately under"info about product". I try with code you gave me but don`t work.
 
If you're gonna have two or more 'lev' elements you need to give them a unique id.

Here is a working sample based on your previous sample.
http://jsfiddle.net/UHnp7/1/

It's better to have a basic idea about CSS, HTML, DOM and JavaScript, before you move on to this type of projects.
 
Yes @himal that is what i want. I need more than 16 'lev' elements. I have idea for css and html but js.... Thank you very much.
 
Status
Not open for further replies.

About the author

N
Established Member · Joined
173
Messages
23
Reactions
18
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom