0

I'm working on store locator of sorts. It is integrated into an order page. The customer inputs their zip and stores around them are displayed in a table with ten rows. I've already set up radio buttons on the end of each row so that the user can select which location they'd like their product shipped to. Each row has the store name, address, and phone number with each chunk of data broken up by class i.e.: ".street-address, .city, .state". the problem is that there are these sets of classes for each table row. I've been wrestling with jquery code to try and find a way to specify that when a radio on the table row is check I want the text from the .street-address from that row to be put as the value of the input field "street-address" in the order form. Any help would be appreciated. I've been trying somethigng along the lines of:

 $('.fflradio').click (function() {$(this).parents('tr').get(".views-field-title").text($("company-name:input").val());});

I know this isn't right as it's obviously not working but any input would be appreciated! Thanks!

4

2 回答 2

1

好吧,没有看到您的 HTML,我无法准确说出选择器的外观,但这可能很接近(并且与您所拥有的相距不远):

$('.fflradio').click(function() {
  $('#id-of-the-address-field').val(
    $(this)
      .closest('tr')
      .find('.street-address')
      .text()
  );
});

现在请注意,如果公司地址字段中有 HTML 标记,您可能会遇到问题。当然,如果您需要填写公司名称、电话号码等,您也会打类似的电话。

于 2010-07-10T19:01:11.407 回答
1

您可能需要重新考虑您的方法。您基本上是在截取您自己的网页以获取您显然已经拥有的信息。我建议将商店地址数据存储在可从单选按钮单击处理程序访问的某种类型的对象中。这样,您的实现不依赖于特定的 UI 布局。

这个简单粗暴的例子应该可以理解这个想法,尽管可能有更好的方法可以做到这一点,我不会在生产中使用这种方法:

// In the code that builds a row in the table, store the address data in an object in the radio button's data dictionary (variables should be self-explanatory):
theRadioButton.data('storeAddress', 
  {
    'street': theStreet,
    'city': theCity,
    'state': theState,
    'postalCode': thePostalCode
  });

// In your event handler, refer to the address object:
$('.fflradio').click(function() {
  var address = $(this).data('storeAddress');
  $('#streetAddressFieldID').val(address.street);
  $('#citysFieldID').val(address.city);
  $('#stateFieldID').val(address.state);
  $('#postalCodeFieldID').val(address.postalCode);
});
于 2010-07-10T19:06:12.103 回答