简体   繁体   中英

Special characters breaking up on onchange

I'm having a problem once again, and as you always helped me solve it, hence i'm here again.

In Joomla, we have created a website used for renting/bookings of Villa's with the portal Jomres.

Now in the backend, we can change the location of a Villa ofcourse, and this work with a dropdownbox with an onchange function.

Now here lies the problem, if we for example, click on: Cala d'Hort Then in the inputfield(not writable) it comes as Cala d. It breaks up everything after the apostrophe.

I've tried a bit with encoding or escaping characters, however it did not work.

The little Javascript that is behind this is:

 function stext(selectid, textid) {
     var select = document.getElementById(selectid);
     var selectvalue = select.value;
     var text = document.getElementById(textid);
     text.value = selectvalue;  
  }

And the HTML:

 <select onchange="stext('select', 'town')" id="select" class="sbox">

Is there a way that it does not break and provides the full name instead of breaking it down? Thank you in advance!

Jeroen

Try seeing how the options of the select box are being populated (if they are being inserted with double-quotes). This should work if that is the case. Try using the console or alert to see which value is being fetched as your "selectValue". If that value is already wrong, that means the options from the select box is being already wrongly populated. Maybe you can provide a jsfiddle of your example and we can look at it more further.

This jsfiddle describes both a working and a non-working example using the JavaScript you provided. The HTML is as follows:

<select id="test1" onchange="stext('test1', 'test2')">
    <option value="Cala d'Hort">Cala d'Hort</option>
    <option value='Cala d'Hort'>Cala d'Hort</option>
</select>
<input id="test2" type="text" disabled />

My guess is that you have incorrectly nested quotes in your option tags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM