开发者

How to re-direct to a page using button in drop down list(options_for_select)

开发者 https://www.devze.com 2023-02-14 01:30 出处:网络
How I can create a drop down list using select_tag \"xyz\", options_for_select or any way where on selecting any option from down list and hitting button will redirect me.

How I can create a drop down list using select_tag "xyz", options_for_select or any way where on selecting any option from down list and hitting button will redirect me.

Any help??

<td> 
  <%= select_tag "options", options_for_select( 
                              [["Dashboard", 
                                "/homes/"+registrar.enrollment_application.id.to_s
                              ]] ) %>
</td> 
<input type="button" value="Select" onclick = "check_options()" > 

if above code is right then all i need to write a javascript??开发者_如何学Go please let me now

function = check_options() { 


If you can use javascript or even jquery on the client side you could set the window.location based on the selected item in the drop down, after you click the button:

HTML: This is how you set up your select list and a button

<select id="options">
  <option value="http://stackoverflow.com">Stack Overflow</option>
  <option value="http://google.com/">Google</option>
</select>
<input type="button" id="optionsbutton" value="Go" />

JavaScript: This is how you wire up the button click to the window redirect

var onButtonClick = function() {
    window.location.replace($("#options").val()) //<--- This gets the selected value
                                                 //     and redirects the window
}

$(document).ready(function(){
    $("#optionsbutton").click(onButtonClick);  //<--- This hooks up the button click
                                               //     to do the onButtonClick function
});

See How to redirect to another webpage in JavaScript/jQuery? for more details.

Update Using Provided Code

You'd just have to make your check_options function find the selected value and set the window location:

var check_options = function() {
  window.location.replace($(" [ use selector for select element ] ").val());
});


You should add javascript like this

function check_options() { 
  window.location = document.getElementById("options").value
}
0

精彩评论

暂无评论...
验证码 换一张
取 消