[SOLVED] Can I use forms like this without javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

[SOLVED] Can I use forms like this without javascript

Post 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.
Last edited by Stryks on Sat Sep 17, 2005 1:31 am, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Re: Can I use forms like this without javascript

Post by wwwapu »

Stryks wrote: or at the very least, a simple way to catch non-javascript users and warn them.
<noscript> is easiest way.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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>
Post Reply