3.0.0

Javascript Pro Question - Load CSV based on drop down selection

Hi All,

I'm struggling to come up with a solution, and wondered if one of you pro's could help out. I have a function that will load a different CSV file in to the grid:

function load(url){
table.setURL(url);
table.request();
}

<button onClick="load('http://URLTONEWFILE.CSV')">Load New File</button>
[code]

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('http://mysite.com/csv/mycolour_myshape.csv')">Load New File</button>
</form>


So the bit i need assistance with is the code required to generate the onClick URL in this format: 'mycolour variable' + '_' + 'myshape variable' + '.csv'

Any ideas?




Pete
July 18,
Hi Pete,

there are many ways to do this, here is one:

<script>
function button_clicked(){
var obj_mycolour = document.getElementById("mycolour");
var mycolour = obj_mycolour.value;
if (mycolour==""){
alert("Please select a colour!");
return;
}
var obj_myshape = document.getElementById("myshape");
var myshape = obj_myshape.value;
if (myshape==""){
alert("Please select a shape!");
return;
}
var url = "http://mysite.com/csv/" + mycolour + "_" + myshape + ".csv";
alert("The link is: " + url);
//load(url);
}
</script>

<form>
<select id="mycolour">
<option value=""> </option>
<option value="red">RED</option>
<option value="yellow">YELLOW</option>
<option value="blue">BLUE</option>
</select>

<select id="myshape">
<option value=""> </option>
<option value="square">SQUARE</option>
<option value="circle">CIRCLE</option>
<option value="triangle">TRIANGLE</option>
</select>

<button onClick="button_clicked()">Load New File</button>
</form>

Good luck!

Ron
July 19,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.