Community discussion forum

Javascript, PHP and Forms :S

  • 3 years ago
    Hey Guys,
        I have written some code, that basically enables the user to first chose "ride" or "holiday" and then the select field is shown appropiate to the type.
    The contents of the select field is stored in a database and is pulled out in php. Now my problem is that if the user has a ride name with a ' in it or other non standard html character it puts in its &# code, so for ' for '. This is fine on pages where PHP echo's the contents directly into the HTML but when PHP echo's it into JavaScript, JavaScript does not turn ' into ' . Can anyone help, the code is below..

    function holidays(){

        var IntPath = document.form1.rideid;
        var TheOptions = IntPath.options.length;
        document.form1.rideid.options.length = 0;
    <?php
    do { 
    ?>
          IntPath.options[IntPath.options.length] = new Option("<?php echo $row_holidays['ridename']?>","<?php echo $row_holidays[rideid]?>");

    <?php

    } while ($row_holidays = mysql_fetch_assoc($holidays));

      $rows = mysql_num_rows($holidays);

      if($rows > 0) {

          mysql_data_seek($holidays, 0);

          $row_rides = mysql_fetch_assoc($holidays);

      }

    ?>
    }

    this outputs:




























    function holidays(){

    var IntPath = document.form1.rideid;
    var TheOptions = IntPath.options.length;
    document.form1.rideid.options.length = 0;
    IntPath.options[IntPath.options.length] = new Option("Amsterdam","15");

    IntPath.options[IntPath.options.length] = new Option("Austrian &#39;Tur de Mur&#39;","17");

    IntPath.options[IntPath.options.length] = new Option("Brittany for Kids","14");

    IntPath.options[IntPath.options.length] = new Option("Cork to Kerry","12");

    IntPath.options[IntPath.options.length] = new Option("Denmark for Kids","10");

    IntPath.options[IntPath.options.length] = new Option("Holland for Kids","11");

    IntPath.options[IntPath.options.length] = new Option("Majorca for Kids","13");

    IntPath.options[IntPath.options.length] = new Option("Ring of Kerry","1");

    }




























  • 3 years ago

    If it's outputting the code as &# values, then it must be doing that when you put the data into the database. Therefore, the fix will be in the code that inserts into the database, rather than the code that extracts the data. (At least I think that's right, from what I can see...)

    Let me see the code that inserts the data into the database and I'll see if I can see the problem Big Smile [:D]

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback