Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/128251-solved-select-box-copies-its-value/
Share on other sites

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

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

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

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.