0

i have a script which can import affiliate csv feeds. With a JavaScript function the shows the categories from the csv feed. But when the categoryname has a ' in it i can't import the feed. So i'd like to replace the symbol '.

Below is a PHP template that produces a JavaScript code in a <script> tag. Can somebody maybe help how i can replace a sign in a JavaScript code?

<script>
    $(document).ready(function() {
        var categorie = $('#categorie').val();
        var scheidingsteken = '<?php echo $import->scheidingsteken; ?>';
        var url = '<?php echo $import->url; ?>';
        var naam = '<?php echo $import->naam; ?>';
        getCategorieen(naam, url, scheidingsteken, categorie, "");

        $('#categorie').change(function() {
            var categorie = $('#categorie').val();
            var scheidingsteken = '<?php echo $import->scheidingsteken; ?>';
            var url = '<?php echo $import->url; ?>';
            var naam = '';
            getCategorieen(naam, url, scheidingsteken, categorie, "");
            /*alert("TODO categorieen ophalen");*/
            /*if(categorie == "")
                $('#volgende').attr('disabled', 'disabled');
            else
                $('#volgende').attr('disabled', '');*/
        });
    });

    function getCategorieen(naam, url, scheidingsteken, categorie, geselecteerd) {
        $("#categorie_mapping").html("<p>De categorieen worden opgehaald</p>");
        $.post('/admin/categorieen_ajax.php', {naam:naam, url:url, scheidingsteken:scheidingsteken, categorie: categorie}, function(data) {
            /*var categorieen = data.split(",");*/
            $("#categorie_mapping").html(data);
        });
    }

</script>
matt
  • 10,892
  • 3
  • 22
  • 34
Wessels
  • 1
  • 1
  • Hello Matt, yes but then for categorie. – Wessels Aug 26 '20 at 09:03
  • Does this answer your question? [Fastest method to replace all instances of a character in a string](https://stackoverflow.com/questions/2116558/fastest-method-to-replace-all-instances-of-a-character-in-a-string) – matt Aug 26 '20 at 09:10
  • Not exactly you code. what is the best place to add this code? Then i'll try. – Wessels Aug 26 '20 at 09:17

1 Answers1

0

Did you try the replace() method?

Having some text in a string variable named str, you would replace the word "primer" like this:

let new = str.replace("primer", "anotherWord");

Lorenzo
  • 64
  • 8