SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Javascript "implode" alternative to PHP "implode"

    HTML Code:
    <html>
    <head>
    <title>Form</title>
    </head>
    
    <body>
    <form action="form.php" method="get">
    <div class=""><input name="field" value="1" type="checkbox"> Option One </div>
    <div class=""><input name="field" value="2" type="checkbox"> Option Two </div>
    <div class=""><input name="field" value="3" type="checkbox"> Option Three </div>
    <input class="fsubmit" src="images/buttons/find.gif" value="Show Threads" type="submit">
    </form>
    </body>
    </html>
    Here is the equation. The form above appends field values to the URL that looks like:

    www.mysite.com/form.php?field=1&field=2&field=3

    What I'm trying to achieve is something like:

    www.mysite.com/form.php?field=1,2,3

    Would someone suggest a way to do that? Not sure if that's got to be a javascript way of doing it, just guessing.

    Thanks.

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In JavaScript Array values can be imploded together into a single string with the 'join' method of the Array Object
    Code JavaScript:
    <script type="text/javascript">
        var testArray = new Array();
        testArray[0] = 'first';
        testArray[1] = 'second';
        testArray[2] = 'third';
     
        alert(testArray.join(',')); // returns the string  'first,second,third'
     
    </script>

    For more details, check this reference.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Kailash.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •