...

View Full Version : Generating a URL based on two drop down box selections.



mattpark
07-19-2009, 12:56 AM
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:


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:


<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.

Philip M
07-19-2009, 08:01 AM
Try this:-


<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"?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum