SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    0 Post(s)
    0 Thread(s)

    This has to be easy....Right?

    Hi All,

    I am trying to add a script that produces a link with values and I am having trouble getting a multi select field to produce the correct URL output.

    For example:

    Code javascript:
    function evalURL() {
      var tempStr = "";
      tempStr += "MyValuetype="+document.form1.MyValuetype.value+"&";
      tempStr += "city=""&";  

    The HTML Looks Like This:
    HTML Code:
      Select Type: 
     <select name="MyValuetype">
        <option value="Type1">Type 1</option>
        <option value="Type2">Type 2</option>
        <option value="Type3">Type 3</option>
        <option value="Type4">Type 4</option>
      </select> (REQUIRED)</font><p>
      <font face="Arial">
      <br />
    That all works ok, however the string above for the city works if my html only selects one city. But I need to Select Multiple cities and have the output reflect that

    Code javascript:
      tempStr += "city=""&";

    HTML Code:
    <font face="Arial">
    Select City:
    <select name="city" multiple="multiple" size="5"> 
    <option selected="selected" value="">All</option>
    <option value="City1,">City 1</option>
    <option value="City2,">City 2</option>
    <option value="City3,">City 3</option>
    <option value="City4,">City 4</option>
    <option value="City5,">City 5</option>
    <option value="City6,">City 6</option>
    <option value="City7,">City 7</option>
    If I select Type 2 for the first selection and Multiple Cities, City 1, 3, 5 & 7 the out put link when I press the submit button should look like this:

    However I get This:
    How do I adjust the String to Allow for multiple selections separated by a comma?

    And another question I had was How do I omit the field all together if it is not selected. If the Form field is any or all or not required by the user it should not be added to the string the output contains the data request but the value is either blank or whatever I tell it, but it messes up the output sting.

    If I did a poor job explaining this, please let me know I will try again.

    Thank You ALL in advance!!!!!
    Last edited by ScallioXTX; Nov 12, 2010 at 12:29. Reason: added syntax highlighting

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Melbourne, AU
    17 Post(s)
    1 Thread(s)
    Try this

    Code JavaScript:
    function evalURL() {
        var tempStr = "", cityStr = "";
        var ob =;
        for(var i=0, max=ob.length; i<max; i++) {
            if (ob.options[i].selected) {
                if (i > 0) cityStr += ", ";
                cityStr += ob.options[i].value;
        tempStr += "MyValuetype="+document.form1.MyValuetype.value+"&";
        tempStr += "city="+cityStr+"&"; 


Posting Permissions

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