Click here to Skip to main content
15,884,058 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I've created a small web page, where i select three values from different drop down boxes(selection boxes). These three values gets concatinated where i build a html webpage address/name from these three values.

After I concatenated these three values in the function, I want to call this function in the form "action" method which will redirect it to the html pageI concatenated.

My problem is, that I can't get the value that I concatenated from the function to redirect to the specefic page. The only value that i get in the address bar of the browser is the function name (javascript:buildstring();)

See my code as below:

XML
<!DOCTYPE html>
<html>
<body>
<script type='text/javascript'>

function buildstring()
{
var button = document.getElementById('Submit Query');
var method = document.getElementById('method').options;
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value) + "_"
          + String(accumulation.value) +
        "_"+ String(radar.value) + ".html";

return str }

</script>

<form action ="javascript:buildstring();" target="_blank">

<select id = "method">
<option selected>Select Method</option selected>
   <option value="Point 200km">Point 200km</option>
   <option value="Point 70km">Point 70km</option>
<select/>

<br />

<select id = "accumulation">
<option selected>Select Accumulation</option selected>
   <option value="24 Hour">24 Hour</option>
   <option value="10 Day">10 day</option>
   <option value="30 Day">30 Day</option>
<select/>

<br />
<select id = "radar">
<option selected>Select Radar</option selected>
<option value="Test1">Test1;/option>
<select/>
<br/>
<button id="Submit Query">Submit Query</button>
</form>
</body>
</html>


What can I change in the <form action ="javascript:buildstring();" target="_blank"> section so that the returned string value in the function can be displayed in the address bar of the browser to redirect to the specific web page name?

Thanks
Posted
Updated 3-Jul-14 10:03am
v3
Comments
Wombaticus 3-Jul-14 18:20pm    
I would try calling your buildstring() function from the onclick event of the submit button isntead, and within that use the setAttribute method to set the forms action property to the string str, and simply return true from the function. I would also suggets removing all spoaces (or repalce them with underscores or hyphens) in the filename/string yuou create.

1 solution

If you insist, try this:
XML
function buildstring()
{
var button = document.getElementById('Submit Query');
var method = document.getElementById('method');  // remove options
var accumulation = document.getElementById('accumulation');
var radar = document.getElementById('radar');

var str = String(method.value) + "_"
          + String(accumulation.value) +
        "_"+ String(radar.value) + ".html";

location.assign(str);  // redirect to the concaternated url
}

</script>

<form action="javascript: buildstring();">

 
<!-- your other code -->
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900