views:

755

answers:

4
    <p class="acp3">
 <label>Status</label>
    <select>
  <% if <option>Active</option> %>
   <%= account["status"] == "Active" %>
  <% elsif <option>Disabled</option> %>
   <%= account["status"] == "Disabled" %>
  <% end %>
    </select>
</p>

I am creating a selector with the html and I want to be able to have it access that variable when the specific selector is choosed. Is there a way to do this with Rails or is there a javascript way of doing it?

A: 

I'm confused. Do you mean want something to happen as soon as the user chooses one of those options, before the form is submitted? If so, you need to do it with Javascript. Ruby isn't running on the user's Web browser.

If you mean you want one of those options to be pre-selected based on the value of the account status, that's certainly something Rails can do. But in that case, your "if" statement is backwards. See the documentation for the Rails select_tag helper; it'll make your life a lot easier.

SFEley
Sorry about the confusion. I want it so as soon as the person chooses the option and then would click the update button <p> <label></label> <%= submit_tag "Update" %> </p>The Ruby code would then run. How would I do that with javascript?
Danish Khan
A: 

The ruby code is trying to capture the value you selected and posted(?), or you are trying to do something different? Also any reason you are creating the raw HTML directly rather than just using the select_tag helper?

naven87
I figured out how to fix it. I could have used the select_tag, but the previous code was already written in the HTML directly so I didn't bother changing it. Does it really help having a select_tag helper compared to writing the HTML directly?
Danish Khan
If it is already written and the options are static, probably not.
naven87
A: 

I figured out how to do it I needed to do this.

<select name="status">
      <option value="active">Active</option>
      <option value="disabled" selected="selected">Disabled</option>

that allowed me to access the options like I wanted too.

Danish Khan
A: 

Hi,

this is my code:

<FORM name="projectlist" method="post" id="projectlist" action="">

    <fieldset>
    <legend>Platform choose:</legend>
    <dl>
            <dt><label for="Platform">Platform:</label></dt>
            <dd><select name="Platform">
        %invoke euTxLog.web.view:getListPlatformView%
        %onerror%
        %value errorMessage%
        %value error%
            %endinvoke%

            %loop getListPlatformOutput/results%
                            <option value="%value ID%">%value APPL%</option>
            %endloop%

          <option value="">Leave Empty</option>
    </select>
</dd>
</dl>

<dl>
<dt><label for="submit"></label></dt>
    <dd><INPUT TYPE=SUBMIT VALUE=" Show ..." onclick="this.form.submit()/></dd>
    <button onclick="this.form.submit()></button> 
</dl>

As you can see, I do just submit the form without redirection to new page.

How to do selected="selected" on record from DB which will equal the value Platform from previous submit?

{the code is in DSP (webMethods)}

ReddySk