1

Have something I'm a bit perplexed by. I have written a very basic function to pass a value from an <option> element nested inside a <select> using the onclick event to another text input. It works fine in Firefox, but isn't working in any other browser, and I can't figure out why, as the console is not showing any errors.

The function looks like this:

function getSPO(spoc)
{
var answer = document.getElementById('ANSWER.TTQ.MENSYS.7.');
answer.value = spoc;
} 

And the HTML looks like this:

<tr><td>Sponsor</td><td>
<select>
<option onclick="getSPO('0000001760')">Oxleas Nhs Trust</option>                                                              
<option onclick="getSPO('0000000876')">Sheffield Northern General Hospital</option>                                       
<option onclick="getSPO('0000001426')">The Royal Hospitals Nhs Trust</option>                                       
<option onclick="getSPO('0000001563')">Coventry Healthcare Nhs Trust</option>                                         
<option onclick="getSPO('0000002713')">Barking, Havering & Redbridge</option>
<option onclick="getSPO('0000012578')">Hammersmith Hospital Nhs Trust</option>                                                     
<option onclick="getSPO('0000012580')">Hammersmith Hospital Nhs Trust</option>
</select>
</td></tr>          

1 Answer 1

3

<option> tag should not have onclick event. Change the code to:

<select onchange="getSPO(this.value);">

Using the onchange event of the drop down itself is the trick. Now, have each number as the value of each option:

<option value="0000001760">Oxleas Nhs Trust</option>                                                              
<option value="0000000876">Sheffield Northern General Hospital</option>
...
Sign up to request clarification or add additional context in comments.

Comments

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.