1

EDIT

I'm still getting an error with repeated information on the page when I use the Direct Sctipt as outlined below.

does anyone have any idea why this might be happening?

ORIGINAL QUESTION

I have radio buttons 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.

My current code checks the Yes Button by default when the page loads, but doesn't trigger the button to take effect and bring up the further options

I'm looking for a way to trigger the Yes button automatically on page load.

I'm New to Magento and don't know anything about Jquery in order to make it work

if someone could take a look at the code and advise me on how to proceed I'd be very grateful

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

EDIT

We worked it out as this

<div class="input-box">
    <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> 
function getdata(){ 
$wk_jq("#wantpartneryes").prop("checked", true); 
$wk_jq("#wantpartneryes").trigger("change"); } setTimeout(getdata,700);
</script>

though it's not perfect, it works but when it triggers the additional option it repeats it's self on the page

Edit

The Direct Code posted in the answer below with the revisions work perfectly

1 Answer 1

0

First you radio button have same id's change. Then add the below jquery. Add this code after the fields:

<div class="input-box">
    <input type="radio" id="wantpartneryes" 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>

<script>

 function getdata(){ 
    $wk_jq("#wantpartneryes").prop("checked", true);
    $wk_jq("#wantpartneryes").trigger("change");
 }

 setTimeout(getdata,700);
</script>

you can also run direct code.

 <script>
           $wk_jq("#wantpartneryes").prop("checked", true);
           $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);
   </script>

after i checked the live code there was jquery error add these line will solve that

var $wk_jq=jQuery.noConflict();

$wk_jq("#wantpartneryes").prop("checked", true); 

$wk_jq("#wantpartneryes").trigger("change");
23
  • thanks for for that, I've made the changes you mentioned but the script isn't triggering the yes button when the page loads. When the page loads it still operates as though non of the buttons have been checked Apr 29, 2016 at 10:18
  • make trigger change to click in both places then check Apr 29, 2016 at 10:25
  • I can see only one instance of the trigger change is there somewhere else I should be changing it also? Apr 29, 2016 at 10:37
  • $wk_jq( ".wantpartner" ).trigger( "click" ); and your function $wk_jq('.wantpartner').click(function(){ Apr 29, 2016 at 10:55
  • like this? <div class="input-box"> <input type="radio" id="wantpartneryes" 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> <script> $wk_jq("#wantpartneryes").prop("checked", true); $wk_jq( ".wantpartner" ).trigger( "click" ); $wk_jq('.wantpartner').click(function(){ </script> Apr 29, 2016 at 11:08

Your Answer

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

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