Log in

View Full Version : help with submitting data using a form



jc_gmk
06-25-2007, 09:06 AM
I am trying to make a form that submits a value as soon as the option is clicked on.
i.e without a submit button.

Is this possible using just HTML?

after searching google I found I can do this using javascript but there must be a simpler way to do it?

tech_support
06-25-2007, 09:16 AM
Is this possible using just HTML?
No.

after searching google I found I can do this using javascript but there must be a simpler way to do it?
No.

With JavaScript, you could just add this to the <option> tag.

onclick="this.form.submit()"

jc_gmk
06-25-2007, 09:23 AM
Thanks, any ideas how i'd write this function using javascript?
I'm know html and php but don't really have alot of knowledge concerning javascript.

also I take it this will affect users that have javascript disabled.

Is there an alternative maybe using php instead?

alexjewell
06-25-2007, 03:14 PM
PHP is server side, so there'd have to be some sort of javascript to connect to the server in order to submit the form this way. Either way, javascript is the way to go for this. You could do something like this for people who have javascript disabled, however:



<noscript>
<input type="submit" value="Submit!" />
</noscript>

jc_gmk
06-25-2007, 03:52 PM
I've now used javascript

here's the code I used:



<script type="text/javascript" language="JavaScript">
function nav()
{
var w = document.sortby.price.selectedIndex;
var url_add = document.sortby.price.options[w].value;
window.location.href = url_add;
}
</script>

Then called the function like this:


<form name="sortby" method="get">
<select name="price" onchange="nav()">
<option value="products.php?sort=ASC">Price (ASC)</option>
<option value="products.php?sort=DESC">Price (DESC)</option>
</select>
</form>

alexjewell
06-25-2007, 04:36 PM
good.

I'd also use the code I gave you for the noscript - for people that don't support javascript.