1

I'm after some help regarding some coding within a Drupal site.

I have page a, which has a list of services offered. page b has a contact form which has a contact form, and at the very top has a dropdown which contains a list of the services offered.

What I'm after is that when a link is pressed on page a, the link that is pressed, sets the dropdown list value to the service that the link corresponds to.

This is the code of the part of the form that I would like changing.

<form class="webform-client-form webform-client-form-37 webform-conditional-processed" 
enctype="multipart/form-data" action="/?q=contactus" 
method="post" id="webform-client-form-37" accept-charset="UTF-8">


<select id="edit-submitted-subject-query1" name="submitted[subject_query1]" class="form-select required">
<option value="Bike Enquiry">Bike Enquiry</option><option value="General" selected="selected">General</option>
  <option value="MOT Appointment Enquiry">MOT Appointment Enquiry</option>
  <option value="Restoration/Service Enquiry">Restoration/Service Enquiry</option>
  <option value="Sponsorship">Sponsorship</option>
  <option value="Other Subject">Other</option>
</select>

Any help would be greatly appreciated!

rdans
  • 2,179
  • 22
  • 32
  • Not sure what you need here, can you rephrase it or maybe create a fiddle. – Farhan Mar 30 '15 at 19:54
  • Is [this](http://jsfiddle.net/cfwksyL5/) what you are trying to achieve? – amura.cxg Mar 30 '15 at 19:56
  • I have used drupal in ages .. but i am pretty sure that you need the views module and taxonomy. –  Mar 30 '15 at 19:59
  • Nearly, @amura.cxg - however the I want the links to be on a separate page, is this possible? So when the link is pressed it takes you to the page with the form on and it changes the value. – Amos Rowell Mar 30 '15 at 20:22
  • @AmosRowell ah I see what you are trying to do. Take a look at [this](http://stackoverflow.com/questions/3724106/how-to-exchange-variables-between-two-html-pages). You could pass the link value in the query string to the page and use that string to select the correct value from the drop down – amura.cxg Mar 30 '15 at 21:33

1 Answers1

0

You would need to pass the selected ID to the other page somehow. Below is an example of how you could pass the ID using a query string. For other options see this question.

Page A

<a href="?id=Sponsorship">Sponsorship</a><br />
<a href="?id=MOT_Appointment_Enquir">MOT Appointment Enquiry</a><br />
<a href="?id=Other_Subject">Other Subject</a><br />

Page B

HTML

<select id="edit-submitted-subject-query1" name="submitted[subject_query1]" class="form-select required">
<option value="Bike_Enquiry">Bike Enquiry</option><option value="General" selected="selected">General</option>
  <option value="MOT_Appointment_Enquiry">MOT Appointment Enquiry</option>
  <option value="RestorationService_Enquiry">Restoration/Service Enquiry</option>
  <option value="Sponsorship">Sponsorship</option>
  <option value="Other_Subject">Other</option>
</select>

JS (in the document load function)

$("#edit-submitted-subject-query1").val(getParameterByName("id"));

//Take from https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

This example doesn't work properly in JSFiddle so I can't send you a working example. Sorry!

Community
  • 1
  • 1
amura.cxg
  • 2,348
  • 3
  • 21
  • 44