budimir Posted October 13, 2008 Share Posted October 13, 2008 Hey guys, Do you know of anyscript where user could choose a value in select box and then automaticlly 3 or more other select boxes would get the same value? For instance: User chooses in selectbox 1 value car And the automaticly selectbox2 gets value car And the automaticly selectbox3 gets value car And the automaticly selectbox4 gets value car And the automaticly selectbox5 gets value car And the automaticly selectbox6 gets value car Or you can point what to search on google! Quote Link to comment Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 This isn't exactly what you're looking for but it should help: Autoselect check boxes Quote Link to comment Share on other sites More sharing options...
budimir Posted October 13, 2008 Author Share Posted October 13, 2008 OK, I'm trying to rework this a little bit and I need your help. My knowledge of javascript is not to good. This is what I have for now: <SCRIPT LANGUAGE="JavaScript"> <!-- // by Nannette Thacker // http://www.shiningstar.net // This script checks and unchecks boxes on a form // Checks and unchecks unlimited number in the group... // Pass the Checkbox group name... // call buttons as so: // <input type=button name="CheckAll" value="Check All" //onClick="checkAll(document.myform.list)"> // <input type=button name="UnCheckAll" value="Uncheck All" //onClick="uncheckAll(document.myform.list)"> // --> <!-- Begin function checkAll(field) { for (i = 0; i < field.length; i++) field[i].selected = true ; ------ I have changed this from "checked" to "selected" } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].selected = false ; } // End --> </script> And for the event I have done this: onChange="checkAll(document.autoSumForm.list) Couple of questions: 1. Is this possible? 2. document.autoSumForm.list -> list is a name of object on a form, is it possible to use ID instead of name???? Quote Link to comment Share on other sites More sharing options...
budimir Posted October 15, 2008 Author Share Posted October 15, 2008 I could go for any other approach if you have ideas! Quote Link to comment Share on other sites More sharing options...
toprashantjha Posted October 15, 2008 Share Posted October 15, 2008 if the value of option to be selected in different select box is same then in that case after changing option in one select box u can get the selected index in JS (using obj.selectedIndex) and can select the other options accordingly(as obj.selectedIndex = val ). Quote Link to comment Share on other sites More sharing options...
budimir Posted October 15, 2008 Author Share Posted October 15, 2008 Can you post some code? I'm not too good with javascript! Quote Link to comment Share on other sites More sharing options...
toprashantjha Posted October 16, 2008 Share Posted October 16, 2008 Look at this code.. if ur need somthing lyk this den it might help u... <html> <body> <script type="text/javascript"> function ChangeVal(Obj) { var selected_option = Obj.selectedIndex; var ctrl_id = Obj.id; switch( ctrl_id ) { case "select1": document.getElementById("select2").selectedIndex = selected_option; break; case "select2": document.getElementById("select1").selectedIndex = selected_option; break; } } </script> <form> <select ID="select1" onchange="ChangeVal(this)"> <option value = 0>Name</option> <option value = 1>Add</option> </select> <select ID="select2" onchange="ChangeVal(this)"> <option value = 0>Name</option> <option value = 1>Add</option> </select> </form> </body> </html> Here if u change option for 1 select box then value for another will automatically changed... Quote Link to comment Share on other sites More sharing options...
budimir Posted October 16, 2008 Author Share Posted October 16, 2008 I think it's exactly what I need. I will try it out and let you know if it worked. Thanks so much. Quote Link to comment Share on other sites More sharing options...
budimir Posted October 20, 2008 Author Share Posted October 20, 2008 @toprashantjha It's exactly what I need, but I have a problem. Here is the code I adjusted: <script type="text/javascript"> function ChangeVal(Obj) { var selected_option = Obj.selectedIndex; var ctrl_id = Obj.id; switch( ctrl_id ) { case "prevozno_sredstvo": document.getElementById("vrsta_prijevoza2").selectedIndex = selected_option; break; case "vrsta_prijevoza2": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; case "vrsta_prijevoza3": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; case "vrsta_prijevoza4": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; case "vrsta_prijevoza5": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; case "vrsta_prijevoza6": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; case "vrsta_prijevoza7": document.getElementById("prevozno_sredstvo").selectedIndex = selected_option; break; } } </script> My problem is, when I change first selecbox, only second select box changes it's value. How can I adjust it so all 6 is changed??? Quote Link to comment Share on other sites More sharing options...
budimir Posted October 20, 2008 Author Share Posted October 20, 2008 I got it!!! This is the code I needed: <script type="text/javascript"> function ChangeVal(Obj) { var selected_option = Obj.selectedIndex; var ctrl_id = Obj.id; switch( ctrl_id ) { case "prevozno_sredstvo": document.getElementById("vrsta_prijevoza2").selectedIndex = selected_option; document.getElementById("vrsta_prijevoza3").selectedIndex = selected_option; document.getElementById("vrsta_prijevoza4").selectedIndex = selected_option; document.getElementById("vrsta_prijevoza5").selectedIndex = selected_option; document.getElementById("vrsta_prijevoza6").selectedIndex = selected_option; document.getElementById("vrsta_prijevoza7").selectedIndex = selected_option; break; } } </script> It's working perfectly!!!! @toprashantjha Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.