Html and Javascript - [HELP]
2014-11-19, 04:09 PM,
#1
Hello Cpaelites.. I have a project, hmm how I can show the value of selected items to textbox using javascript?

Quote:// MY LIST
<select id="list" class="form-control" multiple="">
<option value="2014">Your Cute</option>
<option value="2013">Your Ugly</option>
<option value="2011">Your Awesome</option>
</select>

// BUTTON and TEXTBOX
<button onclick="show_value();" type="button" value="Post Now">Get Value</button>

<input type="text" id="selectedvalue" class="text" name="selectedvalue" style="width: 55%;" />

I came up with this javascript code
Code:
function showgroup_id () {
  $('#selectedvalue').val(selectedvalue);  
  var myList = document.getElementById('list');
var selectedvalue = selectedItem;
            var selectedGroupIds = [];
            for (var i = 0; i < myList.length; i++) {
                if (myList[i].selected) {
                    selectedselectedItem.push(myList[i].value);            
                }
}
}

When I tried the it doesn't work.. anyone can help me please?

How much you can take and keep moving forward.
That's how winning is done!

Reply
Share This Thread :

2015-02-01, 09:53 AM,
#2
You have to change button onclick to showgroup_id() as shown below:
Code:
<!-- MY LIST -->
<select id="list" class="form-control" multiple>
    <option value="2014">Your Cute</option>
    <option value="2013">Your Ugly</option>
    <option value="2011">Your Awesome</option>
</select>
<!-- BUTTON and TEXTBOX -->
<button onclick="showgroup_id();" type="button" value="Post Now">Get Value</button>
<input type="text" id="selectedvalue" class="text" name="selectedvalue" style="width: 55%;" />

Also this javascript code will show all your selected values in the textbox. Enjoy!
Code:
function showgroup_id() {
    var list = document.getElementById("list");
    var textBox = document.getElementById("selectedvalue");
    for (var i = 0; i < list.length; i++) {
        if (list.options[i].selected) {
            textBox.value += list.options[i].value + " ";
        }
    }
}
Reply
2015-02-01, 10:29 AM,
#3
Not sure what you mean here, as for heka's code it didn't do much. What do you exactly want tho?
Reply
2015-02-01, 10:38 AM,
#4
(2015-02-01, 10:29 AM)batdan Wrote: Not sure what you mean here, as for heka's code it didn't do much. What do you exactly want tho?

I just double checked and the code works. So basically dahilan01 wanted to print values of selected droplist items to textbox. batdan: Do you get some kind of error from my code or what? Here is the full code, you can try that too:

Code:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>List</title>
    </head>
    <body>
        <!-- MY LIST -->
        <select id="list" class="form-control" multiple>
            <option value="2014">Your Cute</option>
            <option value="2013">Your Ugly</option>
            <option value="2011">Your Awesome</option>
        </select>
        <!-- BUTTON and TEXTBOX -->
        <button onclick="showgroup_id();" type="button" value="Post Now">Get Value</button>
        <input type="text" id="selectedvalue" class="text" name="selectedvalue" style="width: 55%;" />
    </body>
    <script>
    function showgroup_id() {
        var list = document.getElementById("list");
        var textBox = document.getElementById("selectedvalue");
        for (var i = 0; i < list.length; i++) {
            if (list.options[i].selected) {
                textBox.value += list.options[i].value + " ";
            }
        }
    }
    </script>
</html>
Reply
2015-02-01, 10:42 AM,
#5
(2015-02-01, 10:38 AM)Heka Wrote:
(2015-02-01, 10:29 AM)batdan Wrote: Not sure what you mean here, as for heka's code it didn't do much. What do you exactly want tho?

I just double checked and the code works. So basically dahilan01 wanted to print values of selected droplist items to textbox. batdan: Do you get some kind of error from my code or what? Here is the full code, you can try that too:

Code:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>List</title>
    </head>
    <body>
        <!-- MY LIST -->
        <select id="list" class="form-control" multiple>
            <option value="2014">Your Cute</option>
            <option value="2013">Your Ugly</option>
            <option value="2011">Your Awesome</option>
        </select>
        <!-- BUTTON and TEXTBOX -->
        <button onclick="showgroup_id();" type="button" value="Post Now">Get Value</button>
        <input type="text" id="selectedvalue" class="text" name="selectedvalue" style="width: 55%;" />
    </body>
    <script>
    function showgroup_id() {
        var list = document.getElementById("list");
        var textBox = document.getElementById("selectedvalue");
        for (var i = 0; i < list.length; i++) {
            if (list.options[i].selected) {
                textBox.value += list.options[i].value + " ";
            }
        }
    }
    </script>
</html>

Might have gotten a bit lazy with the copy paste lmao, but it works perfectly fine in jsfiddle now that I pasted it again. My bad, sorry. I guess op was looking for this

jsfiddle.net/shhjsayp/
Reply
2015-02-01, 05:02 PM,
#6
is that a jquery code?
Reply
2015-02-01, 05:11 PM,
#7
(2015-02-01, 05:02 PM)ColdPlay Wrote: is that a jquery code?

No it isn't. The script is only Javascript. What do you want to know about jquery?
Reply


Related Threads
Thread Author Replies Views Last Post
  How to put HTML landing page script in blogger walterzingo 4 452 2018-02-03, 06:55 PM
Last Post: umberblue
  Where should I put <script> tags in HTML? Pirata 5 500 2017-12-03, 11:38 AM
Last Post: Pirata
  Is it possible to convert the landing page protection into javascript? ๖ۣۜPhoenix 5 415 2017-06-09, 11:54 AM
Last Post: tanfirislam
  Help converting Instapage to HTML Leo 4 616 2017-04-19, 07:25 PM
Last Post: EnChanter
  [Urgent] Help With HTML (Form to Email) IndeXer 5 374 2017-02-01, 01:55 AM
Last Post: IndeXer





About Us | Contact Us | CPA Elites | Advertise | Stats

© 2013-2018 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top