Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Generating a URL based on two drop down box selections.

    Hi All,

    Quick query for a javascript pro i think.

    I have a javascript function that will load a CSV file in to a grid:

    Code:
    function load(url){
    table.setURL(url);
    table.request();
    }
    
    <button onClick="load('URLTONEWFILE.CSV')">Load New File</button>
    This works perfectly, however I need to take it a step further to load CSV files, based on user choices from two drop down boxes. Something like this:

    Code:
    <form name="myform"">
    <select name="mycolour">
    <option value="red">RED</option>
    <option value="yellow">YELLOW</option>
    <option value="blue>BLUE</option>
    </select>
    <select name="myshape">
    <option value="square">SQUARE</option>
    <option value="circle">CIRCLE</option>
    <option value="triangle">TRIANGLE</option>
    </select>
    <button onClick="load('/csv/mycolour_myshape.csv')">Load New File</button>
    </form>
    So the bit i need assistance with is the php code required to generate the onClick URL in this format:

    '/folder/' + 'mycolour variable' + '_' + 'myshape variable' + '.csv'
    Any ideas?

    Many thanks for your help.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Try this:-

    Code:
    <form name="myform"">
    <select name="mycolour">
    <option value = "">Choose a colour</option>
    <option value="red" >RED</option>
    <option value="yellow">YELLOW</option>
    <option value="blue">BLUE</option>
    </select>
    <select name="myshape">
    <option avlue = "">Choose a shape</option>
    <option value="square">SQUARE</option>
    <option value="circle">CIRCLE</option>
    <option value="triangle">TRIANGLE</option>
    </select>
    <button onclick="loadit()">Load New File</button>
    </form>
    
    
    <script type = "text/javascript">
    
    function loadit() {
    var mycol = document.myform.mycolour.value;
    var myshp = document.myform.myshape.value;
    if ((mycol == "") || myshp == "") {
    alert ("You must select a colour and a shape");
    return false;
    }
    var file = "/csv/" + mycol + "_" + myshp + ".csv";
    load(file);
    }
    </script>

    So - did anyone dare tell George Stephenson, "It's not Rocket science"?


  •  

    Posting Permissions

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