animockery Posted October 4, 2012 Share Posted October 4, 2012 OK, I have hit a snag and I want to try and make this work if I can. I am trying to add a new text field next to a current list field based on a single selected item. can anyone help me on this? I added the segments that I want this to change. *script* function DbRole(myform){if (document.myform.Accesslevel1.value=="Database Role = "){document.myform.Accesslevel1("DbRole1").setValue(""); AddFields();}} *form* <input name="Accessgroups1" type="text" size="50"> <select name="Accesslevel1"> <option value=""></option> <option value="Read">Read</option> <option value="Write">Write</option> <option value="Read/Write">Read/Write</option> <option value="Update">Update (accounting)</option> <option value="Delete">Delete (Accounting)</option> <option value="Update/Delete (Accounting)">Update/Delete (Accounting)</option> <option onChange="DbRole()" value="Database Role = ">-Database Role-</option> (**the idea is that when this last item is selected a text field will appear next to this list field**) </select> Any help would be appreciated, I am new to this but I have already managed to set up other js that works but this one escapes me at this moment. Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 The onchange event has to go on the <select> element. Then you have to check the value of the selected option. Link to comment Share on other sites More sharing options...
animockery Posted October 4, 2012 Author Share Posted October 4, 2012 OK so I put the onchange in my select but I am not sure how I check the value of the selected option. <select name="Accesslevel1" onChange="DbRole(Accesslevel1.value);"> the if condition should only be when "Database Role" is selected. I also am not sure if I did the "addfeilds()" part right. Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2012 Share Posted October 4, 2012 No. There's no variable called "Accesslevel1"You have to pass a reference to the element in the function. <select name="Accesslevel1" onChange="DbRole(this);"> function DbRole(el) { var value = el.options[el.selectedIndex].value; if(value == "Database Role = ") { // There is no document.myform, this is non-standard and shouldn't be used // Use getElementById() or getElementsByTagName() }} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now