Page 1 of 1

[SOLVED] Can I use forms like this without javascript

Posted: Sun Sep 11, 2005 1:55 am
by Stryks
Hi all,

Basically, I have a list of products which come in different types, and different sizes.

I want to have a product name displayed, followed by a combobox of the types available for that product.

Next to that I want simple images (image submit or straight HREF), with one per size available. On the following page, I then need to be able to see what the product was, what the variation was, and which button was pressed ... or what size was pressed.

Basically, I want to have a dropdown and multiple submit buttons, where I can determine which button was pressed, as well as what was chosen from the dropdown. This needs to be repeated several times in the same screen (separate forms though).

I would really prefer not to use javescript to accomplish this however, or at the very least, a simple way to catch non-javascript users and warn them. As I said though ... I would really prefer not to penalise non javascript users.

Any help would be really great. Cheers.

Posted: Sun Sep 11, 2005 2:15 am
by josh
You can have an intermidiate page, that the links point to before the user is directed to your javascript page, on the inermediate page output javascript to redirect to the final page, also output a meta refresh tag set to 3 seconds or so to refresh to the non-javascript page. If javascript is enabled it will foward the user to the javascript page before the timeout of 3 seconds for the meta tag is reached.

Posted: Sun Sep 11, 2005 7:16 am
by feyd
this doesn't require any Javascript. You use the form input image type for the images, and standard forms for the drop down and whatever else..

Re: Can I use forms like this without javascript

Posted: Sun Sep 11, 2005 10:00 am
by wwwapu
Stryks wrote: or at the very least, a simple way to catch non-javascript users and warn them.
<noscript> is easiest way.

Posted: Sun Sep 11, 2005 8:52 pm
by Stryks
Thanks feyd, that was exactly what I was after.

This is just my quick sample to suss it out .. works a charm (though I dont know if I went about finding that $_POST['size'] key in the best way.

Thanks also for the other suggestions guys, its all been very helpful. :D

Code: Select all

<?php 
	if (isset($_POST['select'])) {
		echo "<br><br>";
		$size = array_keys($_POST['size']);
		echo "you selected item number {$_POST['select']} using button number {$size[0]}.<br><br>";
	}
?>

<form name="form1" method="post" action="test6.php">
	<select name="select">
		<option value="1">List 1 - item 1</option>
		<option value="2">List 1 - item 2</option>
	</select>
   <input name="size[1]" type="image" src="button_1.gif">
   <input name="size[2]" type="image" src="button_2.gif">
   <input name="size[3]" type="image" src="button_3.gif">
</form>
<form name="form2" method="post" action="test6.php">
	<select name="select">
		<option value="3">List 2 - item 1</option>
		<option value="4">List 2 - item 2</option>
	</select>
   <input name="size[1]" type="image" src="button_1.gif">
   <input name="size[2]" type="image" src="button_2.gif">
   <input name="size[3]" type="image" src="button_3.gif">
</form>
<form name="form3" method="post" action="test6.php">
	<select name="select">
		<option value="5">List 3 - item 1</option>
		<option value="6">List 3 - item 2</option>
	</select>
   <input name="size[1]" type="image" src="button_1.gif">
   <input name="size[2]" type="image" src="button_2.gif">
   <input name="size[3]" type="image" src="button_3.gif">
</form>