# 2 onchange functions - 1 jquery, 1 prototype - not working in safari

**URL:** <https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305>\
**Category:** Rails\
**Created:** [August 6, 2009, 1:52pm UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305 "2009-08-06T13:52:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 6, 2009, 1:52pm UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/1 "2009-08-06T13:52:46Z")

</div>

Hi all,

Im using the jNice plugin on a select box in a form of mine. Im also  
calling a custom JS function which uses prototype on the same select  
box.

\<%= f.collection\_select :item\_name, Item.all, :item\_for\_order, :name,  
{ :name =\> “select”, :onchange =\> “item\_row($(this));”} %\>

now both jNice and item\_row() work in FF when i change the selected  
value. But it does not work in Safari. In safari, the page jumps to  
the top when i click on a selection, if i click on it again, jNice  
works. item\_row() does not.

Now im not sure what the problem is. Im using jQuery.noConflict to  
avoid conflict between the two libraries and otherwise, the JS heavy  
page is working fine.

Anyone with any experience/ tips on this one?

Vinay.

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 6:36am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/2 "2009-08-07T06:36:33Z")

</div>

i narrowed down the issue to one line of code in the item\_row  
function. it tries to insert a value into a hidden\_field which is kind  
of hanging inside

 tags. Here’s the HTML and JS code…
## HTML
 .... .... \<%= f.collection\_select :item\_name, Item.all, :item\_for\_order, :name, { :name =\> "select", :onchange =\> "item\_row($(this));"} %\> 
## JS

function item\_row(element){  
…  
id = /\* calculation excluded for brevity \*/  
(element).up(’.row’).down(’.item\_id’).value = id ; //this is the  
line that fails in safari but works in FF  
…  
}

Anything wrong with my HTML structure that Safari is rejecting?

thanks.

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 7:29am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/3 "2009-08-07T07:29:11Z")

</div>

hi  
i faced the similar prob b4 1 month and then i find out this solution  
cange  
the function from onchange to onclick. this onchange not works with  
IE7  
as well.ff works perfectly.

nirosh

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 7:32am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/4 "2009-08-07T07:32:42Z")

</div>

I actually just solved it by putting the hidden\_field inside another

instead of leaving it hanging outside. I have not checked in IE7. thanks for the heads-up! :)

2009/8/7 nirosh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> On Aug 7, 9:35 am, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > type=“hidden” /\>  
> > …
> > 
> > > Vinay.

–  
In Sport We Trust !!!

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 10:35am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/5 "2009-08-07T10:35:56Z")

</div>

On Aug 7, 5:35 am, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anything wrong with my HTML structure that Safari is rejecting?

You shouldn;t have an input element there - The direct children of a  
tr tag should only be td tags (or similar (th etc.))

Fred

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 10:43am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/6 "2009-08-07T10:43:33Z")

</div>

Hmmm.. this is what I have now. Is this ok?

 .... ....

```
 <td>
       <%= f.collection_select :item_name,

```

Item.all, :item\_for\_order, :name, { :name =\> “select”, :onchange =\>  
“item\_row($(this));”} %\>

2009/8/7 Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Fred
> 
> > > calling a custom JS function which uses prototype on the same select  
> > > Now im not sure what the problem is. Im using jQuery.noConflict to  
> > > avoid conflict between the two libraries and otherwise, the JS heavy  
> > > page is working fine.
> > 
> > > Anyone with any experience/ tips on this one?
> > 
> > > Vinay.

–  
In Sport We Trust !!!

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [August 7, 2009, 11:01am UTC](https://www.ruby-forum.com/t/2-onchange-functions-1-jquery-1-prototype-not-working-in-safari/173305/7 "2009-08-07T11:01:41Z")

</div>

## Im actually having another interesting issue with this table structure im having. I provide a link to add another row to the table. The structure is like this.. HTML

```
<%= render :partial => "item", :collection => @order.items %>

<tr

```

onmouseover=“document.getElementById(‘plussign’).style.display=‘block’;”  
onmouseout=“document.getElementById(‘plussign’).style.display=‘none’;”  
id=“empty\_record”\>

|
| |
| 
\<%= add\_item\_link "+" %\>
 |

## \_item.html.erb

## helper method

def add\_item\_link(name)  
link\_to\_function name do |page|  
page.insert\_html :bottom, :items, :partial=\>‘item’, :object =\>  
Item.new  
end  
end

I was using this successfully when my structure was all in

s. I  
just  
inserted a container div with id ‘items’ at the bottom of which i wanted  
the  
new item row. now i cant use 
s in between. How can I achieve this  
functionality? Any ideas?

thanks..

2009/8/7 Vinay S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> ```
> <%= f.collection_select :item_name,
> 
> ```
> 
> > > On Aug 6, 4:51 pm, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > 
> > > > { :name =\> “select”, :onchange =\> “item\_row($(this));”} %\>  
> > > > Anyone with any experience/ tips on this one?
> > > 
> > > > Vinay.
> 
> –  
> In Sport We Trust !!!

–  
In Sport We Trust !!!
