Reputation: 41
I have a Drupal 7 site that I am trying to use Jquery to modify an exposed filter search form using Jquery. It works for some input fields, but not the one I want. Using the code below, test-input-one and test-input-two work fine, but the Drupal generated input field edit-field-s-city-value does not. The Jquery code builds a drop down list then is supposed to update the other input boxes when the user selects something.
I am using drupal_add_js('misc/jscodefile.js'); in my ..views.tpl.php file to include my Jquery code.
The material Jquery code (I added the // comments)
$(document).ready(function($) {
...
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
$("#test-input-one").val(ui.item.mcity); // this works!
$("#test-input-two").val(ui.item.mstate); // this works!
$("#edit-field-s-city-value").val(ui.item.mcity); // this does not work!!
...
});
The HTML generated by drupal with PHP is:
<div id="edit-field-s-city-value-wrapper" class="views-exposed-widget views-widget-filter-field_s_city_value">
<label for="edit-field-s-city-value">
City </label>
<div class="views-widget">
<div class="form-item form-type-textfield form-item-field-s-city-value">
<input type="text" id="**edit-field-s-city-value**" name="field_s_city_value" value="" size="20" maxlength="30" class="form-text" />
</div>
</div>
</div>
<div id="edit-field-s-zip-value-wrapper" class="views-exposed-widget views-widget-filter-field_s_zip_value">
<label for="edit-field-s-zip-value">
Zip (field_s_zip) </label>
<div class="views-widget">
<div class="form-item form-type-textfield form-item-field-s-zip-value">
<input type="text" id="edit-field-s-zip-value" name="field_s_zip_value" value="" size="10" maxlength="10" class="form-text" />
</div>
</div>
</div>
<div class="views-exposed-widget views-submit-button">
<input type="submit" id="edit-submit-test-view" name="" value="Apply" class="form-submit" /> </div>
</div>
<input type="text" id="test-input-one" name="one_value" value="" size="18" maxlength="40" class="form-text">
<input type="text" id="test-input-two" name="two_value" value="" size="6" maxlength="10" class="form-text">
I am thinking there is something funny with the nested divs, css tags or something, but I am at a loss. Thanks.
Upvotes: 3
Views: 586
Reputation: 703
The only way I could imagine this to go wrong is when the id "edit-field-s-city-value" is not unique.
Upvotes: 1