Results 1 to 4 of 4

Thread: Convert submit button to Onchange submit

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Convert submit button to Onchange submit

    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:[

    Code:
    {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!!!
    Last edited by jscheuer1; 10-25-2011 at 04:52 AM. Reason: format

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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?
    Last edited by traq; 10-25-2011 at 02:05 AM.

  3. #3
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    Thanks for replying.

    The page already uses some javascript.

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

    Thanks, Alexandre


    Quote Originally Posted by traq View Post
    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?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •