Reputation: 73
I want to change the value of a param element which has a specific name. In this case the name attribute is 'filter' and it also has an attribute value which I want to change to the selected value 1 , 2 or 3.
jQuery( document ).ready(function() {
$('#list').on('change', function() {
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="list">
<option value="" selected="selected" disabled="disabled">Options</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<object class="paramList" width="939" height="945" style="display: none;">
<param name="test" value="blabla" />
<param name="okok" value="lalala" />
<param name="filter" value="CHANGE"/>
</object>
<div class="result"></div>
Upvotes: 0
Views: 44
Reputation: 49
You should use attribute selector
$('param[name=filter]');
and combine it with
$('#list').find(":selected").text();
$('param[name=filter]').attr('value', $('#list').find(":selected").text())
EDIT: JS fiddle for you https://jsfiddle.net/3vcwmt4m/
it set selected value to the param with choosen name :)
What is more, you could find elements with some masks i.e.
$('td[name^=filter]') // objects those names begins with 'filter'
$('td[name$=filter]') // objects those names ends with 'filter'
$('td[name*=filter]') // objects those names contains 'filter'
Upvotes: 0
Reputation: 22574
You need to use attribute selector and use attr()
function to access the value of the attribute. When you change your drop down value, just change the value of your param with $(this).val()
.
jQuery( document ).ready(function() {
$('#list').on('change', function() {
$('.paramList param[name="filter"]').attr('value', $(this).val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="list">
<option value="" selected="selected" disabled="disabled">Options</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<object class="paramList" width="939" height="945" style="display: none;">
<param name="test" value="blabla" />
<param name="okok" value="lalala" />
<param name="filter" value="CHANGE"/>
</object>
<div class="result"></div>
Upvotes: 1