0

Example: http://jsfiddle.net/FyLr9/

I have a search function for a jQueryMobile 1.3 app that has the ability to add or delete filters from it. I need to get and store the select list value (can do) and then apply that to the search input's name attribute.

HTML :

<div class="js-select" data-role="fieldcontain">
    <label for="search" class="select">Search By</label>
    <select data-role="none" name="select2[]" class="mySelect" data-theme="e">
        <option value="1" selected="selected" > Search1</option>
        <option value="2" >Search2</option>
        <option value="3" >Search3</option>
    </select>
    <div style="width:100%;height:10px;display:block;"></div>
    <label for="search">Search For</label>
    <input type="search" name="" id="search" class="inline" value="" placeholder="Search" data-theme="d" data-inline="true">
    <a type="button" class="closeselect" id="remove" data-icon="minus" data-iconpos="right" data-inline="true" data-theme="d" data-mini="true">Delete Filter</a>
</div>

JS/jQuery :

$(function(){
    $('form').on('change', '.mySelect', function() {
        var value = $(this).val();
        //alert to show I'm getting the value
        alert (value);
        $(this).next('input[type="search"]').attr('name') = value;
    });
});
1
  • 1
    [data-type=search] or [type=text] JQM changes input search to data-type=search for markup enhancement. Commented Jun 23, 2013 at 23:36

1 Answer 1

1
$(this).nextAll('input[type="search"]').attr('name',value);

http://jsfiddle.net/FyLr9/3/

From Omar's comment just use the id to select the element

$(this).nextAll('#search').attr('name',value);
Sign up to request clarification or add additional context in comments.

6 Comments

@DirtyBirdDesign you spacing through me off
jQuery mobile is different. Take it easy =) check this stackoverflow.com/questions/16972701/…
Thanks Musa, was not aware of nextAll
Any idea why this doesn't work with jQuery Mobile? I ran your fiddle and added jQMobile 1.3 and it stopped working
@DirtyBirdDesign Try $(this).nextAll('ui-input-search').find('#search').attr('name',value);
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.