I have a form with two integer-only text boxes, one group of radio buttons, and a submit button. I would like it to take the values of these three inputs, and use them to generate a URL with three variables, like so:
http://domain.com/file.php?var1=&var2=&var3=
EDIT: To clarify, the output is on the page, not in the URL. I have created a php image that displays different things, based on the URL variables, and this image should be able to be used on other sites as the user sees fit.
EDIT2: My basic HTML:
<form>
<input type="text" id="var1" />
<br />
<input type="text" id="var2" />
<br />
<br />
<input type="radio" name="var3" value="1" />
<br />
<input type="radio" name="var3" value="2" />
<br />
<br />
<input type="button" id="URLGenerate" value="Generate" />
</form>
Well, here is how you can solve this problem:
1. Create the HTML
You need to assign a
idto every text box (text boxes are defined as<input type="text"/>in html. Then you need the radio buttons which are defined as<input type="radio"/>. Make sure that all radio buttons have the samenameattribute. Here is a short intro.2. Get the values with Javascript
You can access every element by its id.
3. Change the current URL
After making the URL, you can change it by assigning to
window.locationin Javascript.I guess if someone wants to make it simpler, they have to type the code for you! 😉
Update
Using the code that you added to the question, I created a javascript program that solves the problem:
Here is a JSBin to try it live and you can see the HTML/JS here: http://jsbin.com/itovat/3/edit