Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


FIX suggestion of ip when subnet id is not the same as array index #34

merged 1 commit into from

2 participants


No description provided.


this looks good, in which context would the error happen?


and also, is there an open bug about this? thanks!


New Host: Network tab. I select a domain, then a subnet. I expect an ip address to be autosugested, but without my patch I only get a javascript error:
drop_text is undefined

Our select box looks like:

<select onchange="subnet_selected(this);" name="host[subnet_id]" id="host_subnet_id"><option value=""></option>
<option value="3">kelder (</option></select>

and drop_tet is defined as


subnet_id will be 3 in this case, but there is no 3th array index

I hope you can make sense out of this :)


No open bug that I know of, just something we ran into. Should I always file a bug report, or is just fixing it ok as well?


hmm.. I can't reproduce, which browser is it?


Firefox 11
To reproduce, create a few Subnets, 3 for example. Then delete the first two subnets. Then you should be able to reproduce.


OK, I want to try and reproduce to understand the root of the problem, thanks for the patch!


If it makes it easier to understand:
instead of:

-  var drop_text = $(element).text().split("\n")[subnet_id]
+  var drop_text = $(element).children(":selected").text();

I could also write:

-  var drop_text = $(element).text().split("\n")[subnet_id]
+  var drop_text = $(element).children("[value=" + subnet_id + "]").text();

The important thing is that if some subnets are removed, then you are missing some \n's to split on, so array indexing is off.


what I'm not getting, is why would the returned array is wrong?


Ok, another try:
we have this selectbox:

    <option value=""></option>
    <option value="1">choosing this option will work (</option>
    <option value="3">choosing this option will break (</option>
what you see here is that we once had a subnet with id of 2, but it is removed.
Now the current code does
```var drop_text = $(element).text().split("\n")[subnet_id]```
$(element).text() will be:
 ```<empty line>
choosing this option will work (
choosing this option will break (

Now you split it, and you get the array:
```0 => ''
1 => 'choosing this option will work ('
2 => 'choosing this option will break ('

but since 'value' of the last option is 3, subnet_id will be 3, and
```var drop_text = $(element).text().split("\n")[subnet_id]```
means we try to get index 3 from the array, which doesn't exist.
What you want is to get the text of the option where value==3, not the 3th in the list:
```var drop_text = $(element).children("[value=" + subnet_id + "]").text();```
Or even better, just get the text of the selected element, which is what we are trying to do anyway:
```var drop_text = $(element).children(":selected").text();```
This last one is what my patch does
@ohadlevy ohadlevy merged commit dfcfbae into from
@rbirnie rbirnie referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 16, 2012
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 public/javascripts/host_edit.js
4 public/javascripts/host_edit.js
@@ -123,9 +123,9 @@ function subnet_selected(element){
if (subnet_id == '' || $('#host_ip').size() == 0) return false;
// We do not query the proxy if the host_ip field is filled in and contains an
// IP that is in the selected subnet
- var drop_text = $(element).text().split("\n")[subnet_id]
+ var drop_text = $(element).children(":selected").text();
if (drop_text.length !=0 &&^.+ \([0-9\.\/]+\)/) != -1) {
- var details = $(element).text().split("\n")[subnet_id].replace(/^[^(]+\(/, "").replace(")","").split("/");
+ var details = drop_text.replace(/^[^(]+\(/, "").replace(")","").split("/");
if (subnet_contains(details[0], details[1], $('#host_ip').val()))
return false;
Something went wrong with that request. Please try again.