/    Sign up×
Community /Pin to ProfileBookmark

Generating a URL based on two drop down box selections.

Hi All,

Quick query for a PHP 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(‘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>[/CODE]

So the bit i need assistance with is the php code required to generate the onClick URL in this format:

[QUOTE]

http://www.mysite.com/folder/‘ + ‘mycolour variable’ + ‘_’ + ‘myshape variable’ + ‘.csv’

[/QUOTE]

Any ideas?

Many thanks for your help.

Matt

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@ntk418Jul 18.2009 — I believe this should do the trick:

[CODE]var dynURL = 'http://www.mysite.com/folder/' + mycolour.value + '_' + myshape.value + '.csv';[/CODE]
Copy linkTweet thisAlerts:
@ntk418Jul 18.2009 — I'm sorry, I should have elaborated a bit more.

First you would need to get the object of the element, in that case would be something similar to:

[CODE]var myColour = document.getElementById('mycolour');[/CODE]

This gets us an object named accordingly

Since it is an input field, calling the value attribute from the object should get the currently select option:

[CODE]var myColourOption = myColour.value;[/CODE]

Or:

[CODE]var myColourOption = myColour.getAttribute('value'); [/CODE]

I do not know which one is better to use as far as being more widely supported, but I would use the first.
Copy linkTweet thisAlerts:
@criterion9Jul 19.2009 — Why is this in the PHP section since the question and answer where both javascript?
×

Success!

Help @mattpark spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...