PDA

View Full Version : Convert submit button to Onchange submit



stand247
10-25-2011, 12:41 AM
Hi,

I have a script where I want to change the form submission from using a submit button to "auto" or onChange submit.

My script code is:[


{if $step==1}
<div class="form_content">
<form name="newad" method="post" oaction="newad.php?step=1">
<label>{""}<span class="mandatory"></span></label><br><br>
<select id="category" name="category">
<option value="">{$lng.listings.category}</option>
{foreach from=$categories item=v name=cat}
{if $v.parent==1}
<optgroup label="{$v.str}{$v.name}">
{else}
<option value="{$v.id}" {if $tmp.category==$v.id}selected="selected"{/if}>{$v.str}{$v.name|escape:"html"}</option>
{if ( $smarty.foreach.cat.index!=$categories|@count-1 && $v.parent_id!=$categories[$smarty.foreach.cat.iteration].parent_id) || ($smarty.foreach.cat.index==($categories|@count-1) && $v.parent_id!=0)}
</optgroup>
{/if}

{/if}
{/foreach}
</select>
<br/><br/>

<div class="buttons"><div class align="left">
<button type="submit" name="Choose_categ" class="positive">
{"Criar Anúncio"}
</button>
</div>
<div class="clearfix"></div>

</form>

</div>
</div> {* end form_container *}
{/if} {* end step1 *}
]

Can anyone help me LOOSE the submit button and make this work as onChange submit?

Thanx in advance!!!

traq
10-25-2011, 12:58 AM
Please use the forum's bbcode tags to format your code examples and make them easier to read: [html] html markup goes here [/html ]

Am I correct that all of your "script" is from the Smarty engine? (I've never used Smarty. and I don't know how it handles adding javascript.)

Does your page currently use javascript (and jQuery)?
Do you want the form to simply submit onchange, or do you want it to use ajax?

stand247
10-25-2011, 08:29 AM
Hi,

Thanks for replying.

The page already uses some javascript.

I just want the form to simply submit onchange (no ajax)

Thanks, Alexandre



Please use the forum's bbcode tags to format your code examples and make them easier to read: [html] html markup goes here [/html ]

Am I correct that all of your "script" is from the Smarty engine? (I've never used Smarty. and I don't know how it handles adding javascript.)

Does your page currently use javascript (and jQuery)?
Do you want the form to simply submit onchange, or do you want it to use ajax?

jscheuer1
10-25-2011, 09:01 AM
All other things being equal, which they appear to be - that is that there is only the one select element in the form and that the only other element is the submit button. If I've read that right, simply add the highlighted:


<select id="category" name="category" onchange="this.form.submit();">

But I would advise against doing it. Having a select allows a user to to make a choice, view it and think about it before hitting submit. What you're proposing takes that away from them. Likely there will be more people hitting the back button and scratching there heads than folks saved from unnecessary clicks.