473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript form dropdown to display different selections

Hello,

For a fansite I am trying to implement an easy way to find id's for items.

Basically I want the dropdownfields, here named itemsid,axesid to appear depending on the selection on the itemtype dropdown. Initially itemsid, axeside should be hidden.

Expand|Select|Wrap|Line Numbers
  1. <form name="frmSelect">
  2. <select id="itemtype">
  3.     <option value="itemsid">Items</option>
  4.     <option value="axesid">Axe</option>
  5. </select>
  6. <p id="type-display">none selected</p>
  7. <select id="itemsid" name="itemsid">
  8.     <option value="" selected="selected"></option>
  9.     <option value="f">Gold</option>
  10. </select>
  11. <select id="axesid" name="axesid">
  12.     <option value="" selected="selected"></option>
  13.     <option value="2c672">Ancient Nord War Axe</option>
  14. </select>
  15. </form>
  16.  
Sadly this is all I have at the moment since I am, at most, an apprentice to javascript.
I tried looking at webexamples, but I understand too little of Javascript to adapt it to my needs or haven't found the "right" place for it. The stuff I work on atm looks like this.
Any help would be appreciated, thanks.
Nov 17 '11 #1
5 5139
Expand|Select|Wrap|Line Numbers
  1. <h2 style="margin-top:180px;">Create Item Links</h2>
  2. <script type="text/javascript">
  3. function getskcode() {
  4.     var skcommand = "\"player.additem " + document.getElementById(document.getElementById('itemtype').value).value + " " + document.getElementById('amount').value + "\" or: \"player.placeatme " + document.getElementById(document.getElementById('itemtype').value).value + " " + document.getElementById('amount').value + "\" to place the object at your feet";
  5.     document.getElementById("display").innerHTML = skcommand;
  6. }
  7. function itemtype() {
  8.     var i=1;
  9.     for (i=1;i<=18;i++)
  10.     {
  11.         obj1 = document.getElementById("i");
  12.         obj.style.visibility = 'hidden';
  13.     }
  14.     obj2 = document.getElementById('itemtype').value;
  15.     document.getElementById(obj2).style.visibility = 'visible';
  16. }
  17. </script>
  18. Once more this tool is work in progress!
  19. <form name="frmSelect">
  20. Select a category: <select id="itemtype" onchange='itemtype();'>
  21.     <option value="1">Items</option>
  22.     <option value="2">Axe</option>
  23.     <option value="3">Battleaxe</option>
  24. </select>
  25. Select an item: <select id="1" name="1" onchange='getskcode();'>
  26.     <option value="" selected="selected"></option>
  27.     <option value="f">Gold</option>
  28.     <option value="a">Lockpick</option>
  29. </select>
  30. <select id="2" name="2" onchange='getskcode();'>
  31.     <option value="" selected="selected"></option>
  32.     <option value="2c672">Ancient Nord War Axe</option>
  33.     <option value="8adfb">Ceremonial Axe</option>
  34. </select>
  35. <select id="3" name="3" onchange='getskcode();'>
  36.     <option value="" selected="selected"></option>
  37.     <option value="1cb64">Ancient Nord Battle Axe</option>
  38.     <option value="139b4">Daedric Battleaxe</option>
  39. </select>
  40. <br />
  41. Select the number of items: <select id="amount" name="amount" onchange='getskcode();'>
  42.     <option value="[amount]" selected="selected"></option>
  43.     <option value="1">1</option>
  44.     <option value="2">2</option>
  45.     <option value="3">3</option>
  46.  
  47. </select>
  48. </label>
  49. </form>
  50. Use this code in Skyrim's Console to receive the Item:
  51. <p style="margin:15px 15px 30px 15px;" id="display">Use the dropdown menu to display some console commands here</p>
  52. <p>Special thanks to <a href="http://bytes.com/profile/196795/dormilich/" target="_blank">Dormilich at bytes.com</a> for help with the script!</p>
  53.  
Here is the script as excerpt - whole thing. The idea is, to simply hide everything and then display the one that is active.

Getskcode(); is simply the display of the selected boxes and is working properly

Thanks in advance.
Nov 18 '11 #2
The script works now, in a way ... however it does not add or remove the fields when the main selection drop down menu is being changed, I added the same command to another trigger and it works there without an issue.

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2. function getskcode() {
  3.     var skcommand = "player.additem " + document.getElementById(document.getElementById('itemcat').value).value + " " + document.getElementById('amount').value + "<br /><br /> or: <br /><br />player.placeatme " + document.getElementById(document.getElementById('itemcat').value).value + " " + document.getElementById('amount').value;
  4.     document.getElementById("display").innerHTML = skcommand;
  5. }
  6. function itemcat() {
  7.     var i=1;
  8.     for (i=1;i<=28;i++)
  9.     {
  10.         document.getElementById('dd'+i).style.display="none";
  11.     }
  12.     i = document.getElementById('itemcat').value;
  13.     document.getElementById('dd'+i).style.display="inline";
  14. }
  15. </script>
  16. <select id="itemcat" onchange='itemcat()'>
  17.     <option value="1">Items</option>
  18.     <option value="2">Axes</option>
  19. </select>
  20. <span id="dd1">
  21.     <select id="1" name="1" onchange='getskcode()'>
  22.         <option value="" selected="selected"></option>
  23.         <option value="f">Gold</option>
  24.         <option value="a">Lockpick</option>
  25.         <option value="39be5">Ultimate Healing Potion</option>
  26.     </select>
  27. </span>
  28. <span id="dd2" style="display:none;">
  29.     <select id="2" name="2" onchange='getskcode()'>
  30.         <option value="" selected="selected"></option>
  31.         <option value="2c672">Ancient Nord War Axe</option>
  32.         <option value="8adfb">Ceremonial Axe</option>
  33.     </select>
  34. </span>
  35. <select id="amount" name="amount" onchange='getskcode()'>
  36.     <option value="[amount]" selected="selected"></option>
  37.     <option value="1">1</option>
  38.     <option value="2">2</option>
  39. </select>
  40. <span onclick="itemcat()" class="button">Update</span>
  41. <p style="margin:15px 15px 30px 15px;" id="display">Use the dropdown menu to display some console commands here</p>
  42.  
The html works so far, just when I copy and paste the code into wordpress the dropdown fields do not appear. Any suggestions?

Thanks in advance
Nov 18 '11 #3
One of the Issues turned out to be Wordpress autoformat, I used a plugin called "PS Disable Auto Formatting" and then the autoformat no longer placed <p> and <br /> senseless into the javascript part and it no longer destroyed the spans.

The issue with the function

Expand|Select|Wrap|Line Numbers
  1. <select id="itemcat" onchange='itemcat()'>
Which is not working for some reason. I'd like some input with that. Thanks in advance.
Nov 18 '11 #4
acoder
16,027 Expert Mod 8TB
Do you get any error messages?

What I would suggest is that you rename either the function itemcat() or the ID "itemcat" to something else. Perhaps there is a naming conflict.
Nov 21 '11 #5
Thanks, indeed that seemed to be the issue. Thanks!
Nov 21 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
1
by: abracad | last post by:
Hi Is it possible to use JavaScript to apply different actions to a form depending on a value within the form (eg sending form data to different cgi scripts depending which radio button is...
1
by: Jonathan LaRosa | last post by:
Anyone know how to do this with javascript? I'm trying to avoid creating two different forms because then changes become that much harder to manage. Thanks in advance . . . ~ Jon LaRosa jlarosa...
3
by: Marcus | last post by:
Wondering if it is possible to use one form to open different queries at different times. As an example, I may have frmViewQueries that opens up when I click a command button on frmMain. So, the...
0
by: Nina | last post by:
Hi! I have a frameset (2 cols) which holds a filter in the left frame and will display the search results in the right (content) frame. To do this I set the form target value of the filter...
8
by: lli | last post by:
Hi Guys, I have designed a web application. In its one window I put a form. User can click submit button of this form to run a pathon script to get data from database. Then User get a new window...
1
by: rkinkade | last post by:
Previously I used an .asp Request.Write Request.Form to display the results from a form on a new web page. Is there some similar javascript that I can use? I am no longer using a server that supports...
3
by: ApexData | last post by:
I am using a continuous form for display purposes. Above this form, a single record is displayed so that when the user presses my NewButton they can enter a NewRecord which gets added to the...
1
by: tarabztk | last post by:
MSACCESS 2003 : How to use command buttons to display different subforms I have an application that display information about Pipelines and these pipelines have many other equipments attached to...
2
by: sudhashekhar30 | last post by:
hi all i am using form view. i want to display record in form view from different table. like 1rst time its showing record from tableemp. 2nd time i want to show record of tableSalary in same form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.