I have a dropdown form that I have created - I need to have the dropdown either be auto-generated to a text box once selected or have it placed in the text box once a button has been pressed. For example "Get Hex"
Here is my dropdown:
<fieldset>
<legend>Logos</legend>
<p>
<label>Choose Desired Logo</label>
<select id = "Logo">
<option value = "00">Holden</option>
<option value = "01">HSV</option>
<option value = "02">Chevrolet</option>
<option value = "02">Chevrolet</option>
<option value = "04">CSV</option>
<option value = "05">Pontiac</option>
</select>
<input type="button" value="Show Hex" onclick="displaySelectedItem(val);" />
</p>
<p>
<input type="text" id="Logo" />
</p>
</fieldset>
And here is the last JS script i've tried. I have tried a few but I am surely missing something as nothing I command works.
<script language="JavaScript" type="text/javascript">
<!--
function displaySelectedItem(val)
{
alert(val);
}
//-->
</script>
So I need for the text box to contain the hex code in the <option value = "##">
I'll be using this throughout 6 different forms, all needing the same thing.
Victor Zakharov
26.6k18 gold badges95 silver badges158 bronze badges
-
I would put the onclick event on the select-tagRST– RST2013年05月08日 19:52:03 +00:00Commented May 8, 2013 at 19:52
1 Answer 1
Change
<input type="button" value="Show Hex" onclick="displaySelectedItem(val);" />
to
<input type="button" value="Show Hex" onclick="displaySelectedItem(document.getElementById('Logo').value);" />
answered May 8, 2013 at 19:42
j08691
209k33 gold badges269 silver badges281 bronze badges
Sign up to request clarification or add additional context in comments.
13 Comments
RaphaelDDL
jsfiddle.net/DP5nw/1 --- Here is the updated example with what he wanted, which is
get the value of select and put into input but @Neolisk edited the question and removed that part of what he asked.rfeni
That worked, for the most part. Haha. Why did it do a pop up and not generate to the text field below, as seen in the example?
j08691
I justed used the alert because you did. You can remove it and change it to
document.getElementById('Logo2').value = val; (note that IDs muct be unique and in your example you re-used "Logo"). See jsfiddle.net/j08691/DP5nw/2 rfeni
757goat.org/gto_cluster/Worksheettestjs.php - In the jsfiddle it works perfectly, but in IE and Chrome it results in a popup box. Is this due to something i've commanded?? Edit: This is a link to the document i'm working on. It's a plain jane test site
j08691
Yes it should, although without seeing all your code I can't say with 100% certainty.
|
default