Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make the text field's value blank depending on a condition using jQuery?
    primarykey
    data
    text
    <p>I'm using PHP, MySQL, Smarty and HTML for my website. Now the scenario is I'm having a group of two radio buttons(viz. Yes and No are their values). I'm showing and hiding the textboxes depending on the value of selected radio button. The Hide/Show is working perfectly. The main issue is when I submit the form with radio button selected having value "No" the dependent text fields get hidden but the <code>$_POST[]</code> contains the textfield values present within them, if any. I want to make the values blank of these text fields as the user selects radio button with value "No". Can anyone help me in this regard? Thanks in advance. For your reference I'm putting here the code snippet from my Smarty template as well as the code for Hide/Show functionality.</p> <p>First the code from Smarty template is as follows :</p> <pre><code>&lt;table&gt; &lt;tr height="30"&gt; &lt;td align="right" width="300"&gt;&lt;label&gt;&lt;b&gt;{'Do you want to use call to action ?'|signal_on_error:$error_msg:'newsletter_call_to_action_status'}&lt;/b&gt; &lt;strong style="color: red"&gt;*&lt;/strong&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp; &lt;input type="radio" name="newsletter_call_to_action_status" id="newsletter_call_to_action_status" value="1" onclick="select_option(this.value);" {if $data.newsletter_call_to_action_status=='1' } checked {/if}&gt; Yes &lt;input type="radio" name="newsletter_call_to_action_status" id="newsletter_call_to_action_status" value="0" onclick="select_option(this.value);" {if $data.newsletter_call_to_action_status=='0' } checked {/if}&gt; No &lt;/td&gt; &lt;/tr&gt; &lt;tr id="action_link_no" {if $data.newsletter_call_to_action_status== '1' }style="display:;" {else}style="display:none;"{/if}&gt; &lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="action_link_yes" height="30" {if $data.newsletter_call_to_action_status== '1' }style="display:;" {else}style="display:none;"{/if}&gt; &lt;td align="right" width="300"&gt;&lt;label&gt;&lt;b&gt;{'Enter call to action text'|signal_on_error:$error_msg:'newsletter_call_to_action_text'}&lt;/b&gt; &lt;strong style="color: red"&gt;*&lt;/strong&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;input type="text" name="newsletter_call_to_action_text" id="newsletter_call_to_action_text" value="{if $data.newsletter_call_to_action_status == '0'}{else}{$data.newsletter_call_to_action_text}{/if}" maxlength="50" class="inputfield"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="action_link_yes" height="30" {if $data.newsletter_call_to_action_status== '1' }style="display:;" {else}style="display:none;"{/if}&gt; &lt;td align="right" width="300"&gt;&lt;label&gt;&lt;b&gt;{'Enter call to action link'|signal_on_error:$error_msg:'newsletter_call_to_action_link'}&lt;/b&gt; &lt;strong style="color: red"&gt;*&lt;/strong&gt;&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;input type="text" name="newsletter_call_to_action_link" id="newsletter_call_to_action_link" value="{if $data.newsletter_call_to_action_status == '0'}{else}{$data.newsletter_call_to_action_link}{/if}" class="inputfield"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Now the jQuery code to perform Hide/Show functionality is as follows:</p> <pre><code>{literal} &lt;script language="javascript" type="text/javascript"&gt; function select_option(plan){ if(plan == '0'){ $('#action_link_no').fadeOut('fast'); $('.action_link_yes').fadeOut('fast'); }else{ $('#action_link_no').fadeIn('fast'); $('.action_link_yes').fadeIn('fast'); } } &lt;/script&gt; {/literal} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload