Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What am I missing? 2

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hello,
I borrowed an example from another post to try to do something for a page I'm working on but I seem to have something off.

The desired function of this is to allow the user to select a begining IP range from listbox 1 and then remove that selection and the preceeding selections from listbox 2. IE a range can't equal itself or a ip below the listbox 1 selection.

Code:
<html>
<head>
<title>select changer</title>

<script language="javascript">

function changeSel(sel1,sel2) {
    //  remove options
    
    var curr = sel1.selectedIndex;
    for (x = curr; x <= sel2.options.length - 1; x--){sel2.options[x] = null; x==0;}
}
</script>

</head>

<body>
<form>

<select name="list1" onchange="changeSel(this,this.form.list2);">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>

</select>

<select name="list2">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>
</select>

</form>
</body>
</html>

It seems close but I get an error object doesn't support property or method. If I skip past the error and try to select a new value from listbox 1 I noticed that the increment from the 2'nd selection attemp is added to the increment from the 1'st one.

I'd like the user to have the ability to change the selection as many times as they wish to get the range correct prior to sending the form.

Any ideas?


Thanks, Danzig
 
Code:
for (x = curr; x <= sel2.options.length - 1; x--){sel2.options[x] = null; x==0;}
This starts at the current selected option, then goes to the end by DECREASING the index number? Isn't that like starting at 1 and counting to 10 by negative ones?

As well, why the double equal sign with x==0? What are you comparing for and ignoring the comparison?

Lee
 
Not really sure to be honest but I sure somebody has something that works like this someplace of sees what I did wrong.

I'm not really a jscript person, have been doing vbscript is server side asp but am starting to like the jscript for clientside interaction.


Thanks, Danzig
 
Does this do it?

Code:
function changeSel(sel1,sel2) {
    //  remove options
    
    var curr = sel1.selectedIndex;
    for (x=curr; x>=0; x--){
        sel2.options[x] = null
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
That doesn't generate the object errors but the list2 option removeal still seems to increment with each selection.

IE select 1 time option 10.80.92.2 the next available selection is in listbox2 is 10.80.92.3, but wait I selected the wrong one reselect 10.80.92.4 in listbox1 now the next available in listbox2 is 10.80.92.7. So its keeping track in the slected index and not repopulating listbox2 with the origional selections from listbox1 if you reselect and then reseting the selected index back to 0.

How do I get that to work?
Code:
<html>
<head>
<title>select changer</title>

<script language="javascript">

function changeSel(sel1,sel2) {
    //  remove options
    
    var curr = sel1.selectedIndex;
    for (x=curr; x>=0; x--){
        sel2.options[x] = null
}}
</script>

</head>

<body>
<form>

<select name="list1" onchange="changeSel(this,this.form.list2);">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>

</select>

<select name="list2">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>
</select>

</form>
</body>
</html>


Thanks, Danzig
 
This should do it...
Code:
function changeSel(sel1,sel2) {
    //  remove options
    
    var curr = sel1.selectedIndex;
    curVal = sel1.options[curr].text
    rightNum = curVal.substr(curVal.lastIndexOf(".")+1)
    
    for (x = sel2.options.length-1; x >= 0; x--){
    	curVal = sel2.options[x].text
    	curRightNum = curVal.substr(curVal.lastIndexOf(".")+1)
    	if (parseInt(curRightNum) <= parseInt(rightNum)){
    		sel2.options[x] = null; 
    	}
    }
    sel2.focus()
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
This doesn't have the incrementing issue but say a user selects 10.80.92.5 then listbox2 is 10.80.92.6-20 then they realize that they needed to select 10.80.92.3 not 10.80.92.5 but now listbox2 only contains 6-20 so 10.80.92.4 isn't available for the reselection.


Thanks, Danzig
 
You should have phrased the question that way - can I assume that the last values of the IP will always be between 1 and 20?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
Is this what you want?
Code:
function changeSel(sel1,sel2) {
    //  remove options
    
    var curr = sel1.selectedIndex;
    curVal = sel1.options[curr].text
    rightNum = parseInt(curVal.substr(curVal.lastIndexOf(".")+1))
    
   sel2.options.length = 0
    
    for (x=rightNum + 1; x<=20; x++){
    	sel2.options[x] = new Option("10.80.92."+ x,"")
    }
    

    sel2.focus()
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
Or try this, erase and rebuild? (Problem is to take care users changing their mind and select an ip smaller in the list1!)
Code:
function changeSel(sel1,sel2) {
    var x;
    var curr = sel1.selectedIndex;
    for (x=sel2.options.length-1;x>=0;x--)
        sel2.options[x] = null;
    for (x=0;sel1.options.length-1-sel1.selectedIndex;x++)
        sel2.options[x]=new Option(sel1.options[x+sel1.selectedIndex+1].innerHTML);	
}
- tsuji
 
The actual otions for the listsboxes will be vbscript/sql generated on the serverside. The client side is just to have the logic to deal with the users selections and some light weight rules.

The code that Tsuji posted almost works perfectly but generates errors after selections are made 'options[...].InnerHTML' is null or not an object other wise it would work just great since it will allow for the selections to by dynamically generated on the serverside.


Thanks, Danzig
 
DANZIG,

It is [tt]"[red]i[/red]nnerHTML"[/tt] (case sensitive).

- tsuji
 
Checked it its lowercase still.
Code:
<html>
<head>
<title>select changer</title>

<script language="javascript">

function changeSel(sel1,sel2) {
    var x;
    var curr = sel1.selectedIndex;
    for (x=sel2.options.length-1;x>=0;x--)
        sel2.options[x] = null;
    for (x=0;sel1.options.length-1-sel1.selectedIndex;x++)
        sel2.options[x]=new Option(sel1.options[x+sel1.selectedIndex+1].innerHTML);    
}
</script>

</head>

<body>
<form>

<select name="list1" onchange="changeSel(this,this.form.list2);">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>

</select>

<select name="list2">
<option value="">10.80.92.1</option>
<option value="">10.80.92.2</option>
<option value="">10.80.92.3</option>
<option value="">10.80.92.4</option>
<option value="">10.80.92.5</option>
<option value="">10.80.92.6</option>
<option value="">10.80.92.7</option>
<option value="">10.80.92.8</option>
<option value="">10.80.92.9</option>
<option value="">10.80.92.10</option>
<option value="">10.80.92.11</option>
<option value="">10.80.92.12</option>
<option value="">10.80.92.13</option>
<option value="">10.80.92.14</option>
<option value="">10.80.92.15</option>
<option value="">10.80.92.16</option>
<option value="">10.80.92.17</option>
<option value="">10.80.92.18</option>
<option value="">10.80.92.19</option>
<option value="">10.80.92.20</option>
</select>

</form>
</body>
</html>


Thanks, Danzig
 
DANZIG,

My bad. Drafting up along the thinking! There are something missing in the conditional! This is a re-list.
Code:
function changeSel(sel1,sel2) {
    var x;
    var curr = sel1.selectedIndex;
    //for (x=sel2.options.length-1;x>=0;x--)
    //    sel2.options[x] = null;
    [blue]sel2.options.length = 0;[/blue]
    for (x=0;[red]x<[/red]sel1.options.length-1-sel1.selectedIndex;x++)
        sel2.options[x]=new Option(sel1.options[x+sel1.selectedIndex+1].innerHTML);    
}
Here, I incorporate mwolf's use of .length, which is more concise. This time, it would be about right.

- tsuji
 
You guys are golden Thanks very much both of you.

One day I'll understand the documentm objects and the jscript enough to follow along a little better. Trying to blend both of them at the same time is confusing though at the moment lol.


Thanks, Danzig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top