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


Possibly Related Threads...
Thread Author Replies Views Last Post
  Is it possible to convert the landing page protection into javascript? ๖ۣۜPhoenix 5 199 2017-06-09, 11:54 AM
Last Post: tanfirislam
  Help converting Instapage to HTML Leo 4 388 2017-04-19, 07:25 PM
Last Post: PRINC3
  [Urgent] Help With HTML (Form to Email) IndeXer 5 269 2017-02-01, 01:55 AM
Last Post: IndeXer
  How to make html (php) file loads random js files every time reloading the page? immart247 8 373 2017-02-01, 01:47 AM
Last Post: CharlieHarper
  Alternatives to cpagrip (custom html/css lockers) ArtoAllan 22 3,520 2016-12-17, 07:48 PM
Last Post: COBNET




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

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