# Return back to the view after a javscript condition

**URL:** <https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374>\
**Category:** Rails\
**Created:** [June 3, 2008, 10:32am UTC](https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374 "2008-06-03T10:32:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 3, 2008, 10:32am UTC](https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374/1 "2008-06-03T10:32:28Z")

</div>

Hi  
In the view I have link\_to\_remote as below  
\<%= link\_to\_remote( “Select”,  
{  
:update=\>“div\_inside\_transfer\_reason\_search\_sd”,  
:before=\>“checkgroupselected($(‘sd\_ticket\_primary\_assignee\_group\_id’));”,  
:url =\>{ :controller =\> ‘popup’, :action =\>  
‘transfer\_reason’,:sd\_ticket=\>sd\_ticket,},  
:with =\>"‘transfer\_reason=’+$(‘transfer\_reason’+#{div\_no}).value ‘&’ +  
‘primary\_group\_id=’+$(‘sd\_ticket\_primary\_assignee\_group\_id’).value",  
}) %\>

in the :before i am calling the javascript to check whether the value  
sd\_ticket\_primary\_assignee\_group\_id is empty or not…What i need is if  
that field is not empty only controle goes to the action  
transfer\_reason…Otherwise that is if it is empty I have to show a  
hidden div…And i tried javascript like

But is not working…What may be the reason?Also is there any other  
method as a solution?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 3, 2008, 11:30am UTC](https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374/2 "2008-06-03T11:30:52Z")

</div>

On Jun 3, 9:32 am, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }) %\>  
> {  
> return false;  
> }
> 
> ```
> }
> 
> ```
> 
> But is not working…What may be the reason?Also is there any other  
> method as a solution?

Well you haven’t said in what way is it not working: is it continuing  
when it shouldn’t, stopping when it should continue etc… At the very  
least your checkgroupselected needs a return true in there, and  
you’ve got a syntax error in your :with option (missing a + before  
the &) and you’re not using encodeURIComponent so weird stuff will  
happen if either of those form elements include a &

Fred

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 3, 2008, 11:39am UTC](https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374/3 "2008-06-03T11:39:28Z")

</div>

Hi  
It is working in the sense it is continuing…But i want not  
continuing if the script evaluates false

Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 3, 2008, 11:40am UTC](https://www.ruby-forum.com/t/return-back-to-the-view-after-a-javscript-condition/139374/4 "2008-06-03T11:40:38Z")

</div>

Hi  
Also all was working till adding :before clause  
Sijo
