0

I have a radio button on my site with the options of YES and NO. when set to yes it brings up a further option of the user to input.

By Default it is set checked as Yes, but at the moment the default setting is creating the script to repeat the further option at the bottom of the page

this is the code:

 <div class="hidden">
    <input type="radio" id="wantpartneryes" class="wantpartner" name="wantpartner" value='1' title="<?php echo $helper->__('Agree as Seller') ?>" /> <?php echo $helper->__("Yes"); ?>&nbsp;&nbsp;
    <input type="radio" id="wantpartner" class="wantpartner" name="wantpartner" value='0' title="<?php echo $helper->__('Disagree as Seller') ?>" /> <?php echo $helper->__("No"); ?>
</div>


 <script>
var $wk_jq=jQuery.noConflict();
           $wk_jq("#wantpartneryes").prop("checked", true);
$wk_jq("#wantpartneryes").trigger("change");
           $wk_jq('.button').attr('disabled','disabled');
            $username=$wk_jq('<li/>').addClass('profileurl')
                                    .append($wk_jq('<label/>')
                                        .addClass('required')
                                        .text('<?php echo $helper->__('reFashion Name'); ?>')
                                        .append($wk_jq('<em/>').text('*')))
                                    .append('<?php echo $shopurl_hint ?>')
                                    .append($wk_jq('<div/>')
                                        .addClass('input-box')
                                        .append($wk_jq('<input/>').addClass('input-text')
                                            .attr('title','<?php echo $helper->__(' Your reFashion profile name ')?>')
                                            .addClass('required-entry')
                                            .attr('type','text')
                                            .attr('name','profileurl'))
                                        .append($wk_jq('<span/>')
                                            .text('<?php echo $helper->__(" (Displayed in your public profile) ")?>')
                                            .addClass('required-entry')
                                            .attr('type','text'))
                                    )
                                    .append($wk_jq('<div/>')
                                        .attr('id','wk_load_conf')
                                        .append($wk_jq('<img/>')
                                            .attr('src','<?php echo $this->getSkinUrl('marketplace/images/ajax-loader-tr.gif'); ?>')
                                            .attr('height','20px')
                                            .attr('width','20px')));
            //$wk_jq('#wantptr').next('li').after($username);
            $wk_jq('#wantptr').after($username);
   </script>

does anyone have an idea of how to correct this?

EDIT

this is the whole code`:

    <script type="text/javascript">
    if (typeof jQuery == 'undefined'){
        document.write(unescape("%3Cscript src='//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
</script>
<?php 
$helper=Mage::helper('marketplace'); 
$profile_hint_status = $helper->getProfileHintStatus();
?>
<li class="field" id="wantptr">
    <!-- <label for="wantpartner" class="required"><?php echo $helper->__('Do You Want To Become A Seller / Vendor?') ?> </label> -->
    <?php
    if($profile_hint_status && Mage::getStoreConfig('marketplace/marketplace_profile/become_seller',Mage::app()->getStore())){?>
        <img src="<?php echo $this->getSkinUrl('marketplace/images/quest.png'); ?>" class='questimg' title="<?php echo Mage::getStoreConfig('marketplace/marketplace_profile/become_seller',Mage::app()->getStore()) ?>"/>
    <?php
    } ?>
    <div class="hidden">
    <input type="radio" id="wantpartneryes" class="wantpartner" name="wantpartner" value='1' title="<?php echo $helper->__('Agree as Seller') ?>" /> <?php echo $helper->__("Yes"); ?>&nbsp;&nbsp;
    <input type="radio" id="wantpartner" class="wantpartner" name="wantpartner" value='0' title="<?php echo $helper->__('Disagree as Seller') ?>" /> <?php echo $helper->__("No"); ?>
</div>


 <script>
var $wk_jq=jQuery.noConflict();
           $wk_jq("#wantpartneryes").prop("checked", true);
$wk_jq("#wantpartneryes").trigger("change");
           $wk_jq('.button').attr('disabled','disabled');
            $username=$wk_jq('<li/>').addClass('profileurl')
                                    .append($wk_jq('<label/>')
                                        .addClass('required')
                                        .text('<?php echo $helper->__('reFashion Name'); ?>')
                                        .append($wk_jq('<em/>').text('*')))
                                    .append('<?php echo $shopurl_hint ?>')
                                    .append($wk_jq('<div/>')
                                        .addClass('input-box')
                                        .append($wk_jq('<input/>').addClass('input-text')
                                            .attr('title','<?php echo $helper->__(' Your reFashion profile name ')?>')
                                            .addClass('required-entry')
                                            .attr('type','text')
                                            .attr('name','profileurl'))
                                        .append($wk_jq('<span/>')
                                            .text('<?php echo $helper->__(" (Displayed in your public profile) ")?>')
                                            .addClass('required-entry')
                                            .attr('type','text'))
                                    )
                                    .append($wk_jq('<div/>')
                                        .attr('id','wk_load_conf')
                                        .append($wk_jq('<img/>')
                                            .attr('src','<?php echo $this->getSkinUrl('marketplace/images/ajax-loader-tr.gif'); ?>')
                                            .attr('height','20px')
                                            .attr('width','20px')));
            //$wk_jq('#wantptr').next('li').after($username);
            $wk_jq('#wantptr').after($username);
   </script>


</li>
<script>
<?php
if($profile_hint_status && Mage::getStoreConfig('marketplace/marketplace_profile/shopurl_seller',Mage::app()->getStore())){
    $shopurl_hint = '<img src="'.$this->getSkinUrl('marketplace/images/quest.png').'" class="questimg" title="'.Mage::getStoreConfig('marketplace/marketplace_profile/shopurl_seller',Mage::app()->getStore()).'"/>';

}else{
    $shopurl_hint = '';
} ?>
var $wk_jq= jQuery.noConflict();
$wk_jq(function(){
    $wk_jq('#email_address').parents('li').after($wk_jq('#wantptr'));
    $wk_jq('#wantptr').show();

    $wk_jq('.wantpartner').change(function(){
        if($wk_jq(this).val()==1){
            $wk_jq('.button').attr('disabled','disabled');
            $username=$wk_jq('<li/>').addClass('profileurl')
                                    .append($wk_jq('<label/>')
                                        .addClass('required')
                                        .text('<?php echo $helper->__('reFashion Name'); ?>')
                                        .append($wk_jq('<em/>').text('*')))
                                    .append('<?php echo $shopurl_hint ?>')
                                    .append($wk_jq('<div/>')
                                        .addClass('input-box')
                                        .append($wk_jq('<input/>').addClass('input-text')
                                            .attr('title','<?php echo $helper->__(' The name of your reFashion Profile ')?>')
                                            .addClass('required-entry')
                                            .attr('type','text')
                                            .attr('name','profileurl'))
                                        .append($wk_jq('<span/>')
                                            .text('<?php echo $helper->__(" (This will be displayed your public profile) ")?>')
                                            .addClass('required-entry')
                                            .attr('type','text'))
                                    )
                                    .append($wk_jq('<div/>')
                                        .attr('id','wk_load_conf')
                                        .append($wk_jq('<img/>')
                                            .attr('src','<?php echo $this->getSkinUrl('marketplace/images/ajax-loader-tr.gif'); ?>')
                                            .attr('height','20px')
                                            .attr('width','20px')));
            //$wk_jq('#wantptr').next('li').after($username);
            $wk_jq('#wantptr').after($username);
        }else{
            $wk_jq('.button').removeAttr('disabled');
            $wk_jq('.profileurl').remove();
        }
    });
    $wk_jq('ul').delegate('.profileurl input','keyup',function(){
        $wk_jq(this).val($wk_jq(this).val().replace(/[^a-z^A-Z^0-9\.\-]/g,''));
    });
    $wk_jq('#form-validate').delegate('.profileurl input','change', function(){
        $wk_jq('.unavailable,.available').remove();
        var profileurl=$wk_jq('.profileurl input').val();
        $wk_jq('.button').attr('disabled','disabled');
        if(profileurl!=''){
            $wk_jq('#wk_load_conf').show();
            $wk_jq.ajax({
                url:'<?php echo $this->getUrl("marketplace/seller/usernameverify")?>',
                type:'POST',
                data:{profileurl:profileurl},
                dataType:'JSON',
                success:function(data){
                    $wk_jq('#wk_load_conf').hide();
                    if(data==0){
                        $wk_jq('.button').removeAttr('disabled');
                        $wk_jq('.profileurl').append($wk_jq('<span/>').addClass('available success-msg').text('<?php echo $helper->__("available")?>'));
                    }else{
                        $wk_jq('.profileurl').append($wk_jq('<span/>').addClass('unavailable error-msg').text('<?php echo $helper->__("unavailable")?>'));
                    }
                }
            });
        }
    });
});
</script>

un-modified code:

<script type="text/javascript">
    if (typeof jQuery == 'undefined'){
        document.write(unescape("%3Cscript src='//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
</script>
<?php 
$helper=Mage::helper('marketplace'); 
$profile_hint_status = $helper->getProfileHintStatus();
?>
<li class="field" id="wantptr">
    <label for="wantpartner" class="required"><?php echo $helper->__('Do You Want To Become A Seller / Vendor?') ?> </label>
    <?php
    if($profile_hint_status && Mage::getStoreConfig('marketplace/marketplace_profile/become_seller',Mage::app()->getStore())){?>
        <img src="<?php echo $this->getSkinUrl('marketplace/images/quest.png'); ?>" class='questimg' title="<?php echo Mage::getStoreConfig('marketplace/marketplace_profile/become_seller',Mage::app()->getStore()) ?>"/>
    <?php
    } ?>
    <div class="input-box">
        <input type="radio" id="wantpartner" class="wantpartner" name="wantpartner" value='1' title="<?php echo $helper->__('Agree as Seller') ?>" checked /> <?php echo $helper->__("Yes"); ?>&nbsp;&nbsp;
        <input type="radio" id="wantpartner" class="wantpartner" name="wantpartner" value='0' title="<?php echo $helper->__('Disagree as Seller') ?>" /> <?php echo $helper->__("No"); ?>
    </div>
</li>
<script>
<?php
if($profile_hint_status && Mage::getStoreConfig('marketplace/marketplace_profile/shopurl_seller',Mage::app()->getStore())){
    $shopurl_hint = '<img src="'.$this->getSkinUrl('marketplace/images/quest.png').'" class="questimg" title="'.Mage::getStoreConfig('marketplace/marketplace_profile/shopurl_seller',Mage::app()->getStore()).'"/>';

}else{
    $shopurl_hint = '';
} ?>
var $wk_jq= jQuery.noConflict();
$wk_jq(function(){
    $wk_jq('#email_address').parents('li').after($wk_jq('#wantptr'));
    $wk_jq('#wantptr').show();

    $wk_jq('.wantpartner').change(function(){
        if($wk_jq(this).val()==1){
            $wk_jq('.button').attr('disabled','disabled');
            $username=$wk_jq('<li/>').addClass('profileurl')
                                    .append($wk_jq('<label/>')
                                        .addClass('required')
                                        .text('<?php echo $helper->__('Shop URL'); ?>')
                                        .append($wk_jq('<em/>').text('*')))
                                    .append('<?php echo $shopurl_hint ?>')
                                    .append($wk_jq('<div/>')
                                        .addClass('input-box')
                                        .append($wk_jq('<input/>').addClass('input-text')
                                            .attr('title','<?php echo $helper->__(' Shop URL For Your Marketplace Shop ')?>')
                                            .addClass('required-entry')
                                            .attr('type','text')
                                            .attr('name','profileurl'))
                                        .append($wk_jq('<span/>')
                                            .text('<?php echo $helper->__(" (This will be used to display your public profile) ")?>')
                                            .addClass('required-entry')
                                            .attr('type','text'))
                                    )
                                    .append($wk_jq('<div/>')
                                        .attr('id','wk_load_conf')
                                        .append($wk_jq('<img/>')
                                            .attr('src','<?php echo $this->getSkinUrl('marketplace/images/ajax-loader-tr.gif'); ?>')
                                            .attr('height','20px')
                                            .attr('width','20px')));
            //$wk_jq('#wantptr').next('li').after($username);
            $wk_jq('#wantptr').after($username);
        }else{
            $wk_jq('.button').removeAttr('disabled');
            $wk_jq('.profileurl').remove();
        }
    });
    $wk_jq('ul').delegate('.profileurl input','keyup',function(){
        $wk_jq(this).val($wk_jq(this).val().replace(/[^a-z^A-Z^0-9\.\-]/g,''));
    });
    $wk_jq('#form-validate').delegate('.profileurl input','change', function(){
        $wk_jq('.unavailable,.available').remove();
        var profileurl=$wk_jq('.profileurl input').val();
        $wk_jq('.button').attr('disabled','disabled');
        if(profileurl!=''){
            $wk_jq('#wk_load_conf').show();
            $wk_jq.ajax({
                url:'<?php echo $this->getUrl("marketplace/seller/usernameverify")?>',
                type:'POST',
                data:{profileurl:profileurl},
                dataType:'JSON',
                success:function(data){
                    $wk_jq('#wk_load_conf').hide();
                    if(data==0){
                        $wk_jq('.button').removeAttr('disabled');
                        $wk_jq('.profileurl').append($wk_jq('<span/>').addClass('available success-msg').text('<?php echo $helper->__("available")?>'));
                    }else{
                        $wk_jq('.profileurl').append($wk_jq('<span/>').addClass('unavailable error-msg').text('<?php echo $helper->__("unavailable")?>'));
                    }
                }
            });
        }
    });
});
</script>
3
  • Can you further explain what you mean by your second sentence? I don't quite understand what the problem is.
    – SixShields
    Apr 28, 2016 at 1:12
  • Please show your code for "further option" that appears when "Yes" is checked through a click.
    – dchayka
    Apr 28, 2016 at 3:32
  • what i mean is I have a form with two radio buttons, YES and NO, with one of the options, YES, pre-checked when the page loads. With YES checked it should bring up an additional option, but when the page loads the checked button does not automatically have the desired effect of bringing the additional option that it should, it operates as though no button is selected, in order for it to work I have to click the NO button and then click back to the YES Apr 28, 2016 at 13:36

1 Answer 1

1

Based on my understanding you have the following situation:

2 radio buttons, when the radio button with label "Yes" is clicked another option for user appears (text or radio, etc).

You're attempt is to programmatically trigger the second option to appear by setting one of the radio buttons to checked value.

I believe your problem is that second user input is trigged using Javascript (prototype 1.9 or jQuery because it's Magento 1.9) event.

jQuery solution (you can look up Prototype yourself) is to manually trigger the event when page loads.

Easier solution is to remove the CSS display:none rule on that element (which shows up when you choose "yes") since you already pre-checked the radio button with label "Yes" in your piece of code.

7
  • Hi @dchayka thanks i think you are right about the Javascript, but there is no CSS display:none rule to remove. I'm new to Magento and JQuery so don't really know how to proceed Apr 28, 2016 at 13:33
  • @New2Magento could you post raw HTML of the element before it shows up using the onclick event of your radio button.
    – dchayka
    May 3, 2016 at 13:59
  • Hey I managed to get this working using a script so it triggers automatically, but it's repeating the second option at the bottom of the page, do you have any idea why that might be happening? May 3, 2016 at 14:08
  • @New2Magento it's hard to say without seeing the code.
    – dchayka
    May 3, 2016 at 14:49
  • I've updated the question with the code I used May 3, 2016 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.