Trigger Custom fields from radio field :)

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #17832

how can i make a selection from the form trigger some other fields show? i just need some hints, i think I'll be able to make it happen with PHP.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 5 months ago #17842

By default all the custom fields are shown.
If you want to only display some of them and not others, it means that you will have to edit the file fields of the view checkout via the menu Display->Views and add your code in order to hide/display fileds based on other fields value. I would do it in javascript...

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #17854

damn... know i have no idea how to use JS lol.. thanks for the hint tho i'll look into it..

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 2 months ago #26185

<?php
/**
 * @package    HikaShop for Joomla!
 * @version    1.5.1
 * @author    hikashop.com
 * @copyright  (C) 2010-2011 HIKARI SOFTWARE. All rights reserved.
 * @license    http://www.hikashop.com/commercial_license.php
 */
defined('_JEXEC') or die('Restricted access');
$c1=false;
$c1 = $_SESSION['c1'];

?>
<?php

  $js = "
<!--


var doextra = false;
   if(){
doextra =true;
    var hide = new Array();
    var show = new Array();
     if(choice='1'){
      show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(obj.id=='user_choice_activate_plan_other_phone'){
       show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       show.push('esnnumber');
       show.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(obj.id=='user_choice_activate_plan_iq_phone'){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     else if(obj.id=='user_choice_activate_phone'){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     

  else if(obj.name=='data[order][numberchoice]'){
       var hide = new Array();  
       var show = new Array();  
       if(obj.id=='numberchoice_keepnumber'){  
       show.push('customtext_173_13_32_23');  
       show.push('accountname');  
       show.push('billingaddress');  
       show.push('phone_number');  
       show.push('carrier');  
       show.push('account_number');  
       show.push('pin');  
       show.push('ssn');        
}  
else if(obj.id=='numberchoice_newnumber'){  
       hide.push('customtext_173_13_32_23');  
       hide.push('accountname');  
       hide.push('billingaddress');  
       hide.push('phone_number');  
       hide.push('carrier');  
       hide.push('account_number');  
       hide.push('pin');  
       hide.push('ssn');  
}    
   }  
switchFields(show,hide);
if(doextra){
var keepnumber = document.getElementById('numberchoice_keepnumber');
if(keepnumber.checked){
hikashopHandleCases(keepnumber);
}
}


   
}




function switchFields(show,hide){
 for(var i=0;i<show.length;i++){
   var found = hikashopGetElementsByClass('hikashop_checkout_'+show[i]+'_line',document,'tr');
   for(var k=0; k<found.length;k++){
      found[k].style.display = '';
   }
 }
 for(var j=0;j<hide.length;j++){
  var found2 = hikashopGetElementsByClass('hikashop_checkout_'+hide[j]+'_line',document,'tr');
  for(var l=0; l<found2.length;l++){ found2[l].style.display = 'none'; }
   
 }
}

function hikashopGetElementsByClass( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = \" \"+searchClass+\" \";
  for(i=0,j=0; i<tags.length; i++) {
    var test = \" \" + tags[i].className + \" \";
    if (test.indexOf(tcl) != -1)
      el[j++] = tags[i];
  }
  return el;
}

do_nothing( function(){
  var elements = document.getElementsByName(\"data[order][user_choice]\");
  for(var i=0,j=0; i<elements.length; i++) {
   if(elements[i].checked){
     hikashopHandleCases(elements[i]);
   }
 }
  
});

-->
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($js);
  $type = $this->type;
  foreach($this->extraFields[$type] as $fieldName => $oneExtraField) {  $css='';
 if($fieldName!='user_choice'){
 $css = 'style="display:none;"';
}

  ?>
    <tr class="hikashop_checkout_<?php echo $fieldName;?>_line" <?php echo $css; ?>>
      <td class="key">
        <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
      </td>
      <td>
        <?php
            echo $this->fieldsClass->display($oneExtraField,$this->$type->$fieldName,'data['.$type.']['.$fieldName.']', false, 'onclick=" hikashopHandleCases(this);"');
        ?>
      </td>
    </tr>
  <?php }  ?>


i need to make a modification to this custom code you provide via a service. i need to trigger the fields via the var choice. the var will have the values of 1,2,3, and 4 for each selection on the radio selection. i need to also hide the fields that let you select the option. the var choice will be passed from a session var.


Thank you so much for your help... i am almost done with this project..

Last edit: 13 years 2 months ago by Rickhavoc.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 2 months ago #26200

You're missing some js code at the beginning. There should be something like that:
function hikashopHandleCases(obj){

which I don't see.

For the $c1 variable, you can use it in your js like that:

if('".$c1."'==1){
// do stuff
}else if('".$c1."'==2){
// do stuff
}else{
// do stuff
}

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 2 months ago #26215

isn't the function triggered by the selection of the radio selections? i just want to hide the selections and just show the fields that are coming through with the value of $c1..

here is my shoot in the dark at it.

$c1=false;
$c1 = $_SESSION['c1'];

?>
<?php

  $js = "
<!--
var choice= $c1;
function hikashopHandleCases(obj){

var doextra = false;
   if(){
doextra =true;
    var hide = new Array();
    var show = new Array();
     if(".$c1."'==1){
      show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(".$c1."'==2){
       show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       show.push('esnnumber');
       show.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(".$c1."'==3){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     else if(".$c1."'==4){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     

  else if(obj.name=='data[order][numberchoice]'){
       var hide = new Array();  
       var show = new Array();  
       if(obj.id=='numberchoice_keepnumber'){  
       show.push('customtext_173_13_32_23');  
       show.push('accountname');  
       show.push('billingaddress');  
       show.push('phone_number');  
       show.push('carrier');  
       show.push('account_number');  
       show.push('pin');  
       show.push('ssn');        
}  
else if(obj.id=='numberchoice_newnumber'){  
       hide.push('customtext_173_13_32_23');  
       hide.push('accountname');  
       hide.push('billingaddress');  
       hide.push('phone_number');  
       hide.push('carrier');  
       hide.push('account_number');  
       hide.push('pin');  
       hide.push('ssn');  
}    
   }  
switchFields(show,hide);
if(doextra){
var keepnumber = document.getElementById('numberchoice_keepnumber');
if(keepnumber.checked){
hikashopHandleCases(keepnumber);
}
}


   
}




function switchFields(show,hide){
 for(var i=0;i<show.length;i++){
   var found = hikashopGetElementsByClass('hikashop_checkout_'+show[i]+'_line',document,'tr');
   for(var k=0; k<found.length;k++){
      found[k].style.display = '';
   }
 }
 for(var j=0;j<hide.length;j++){
  var found2 = hikashopGetElementsByClass('hikashop_checkout_'+hide[j]+'_line',document,'tr');
  for(var l=0; l<found2.length;l++){ found2[l].style.display = 'none'; }
   
 }
}

function hikashopGetElementsByClass( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = \" \"+searchClass+\" \";
  for(i=0,j=0; i<tags.length; i++) {
    var test = \" \" + tags[i].className + \" \";
    if (test.indexOf(tcl) != -1)
      el[j++] = tags[i];
  }
  return el;
}

do_nothing( function(){
  var elements = document.getElementsByName(\"data[order][user_choice]\");
  for(var i=0,j=0; i<elements.length; i++) {
   if(elements[i].checked){
     hikashopHandleCases(elements[i]);
   }
 }
  
});

-->
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($js);
  $type = $this->type;
  foreach($this->extraFields[$type] as $fieldName => $oneExtraField) {  $css='';
 if($fieldName!='user_choice'){
 $css = 'style="display:none;"';
}

  ?>
    <tr class="hikashop_checkout_<?php echo $fieldName;?>_line" <?php echo $css; ?>>
      <td class="key">
        <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
      </td>
      <td>
        <?php
            echo $this->fieldsClass->display($oneExtraField,$this->$type->$fieldName,'data['.$type.']['.$fieldName.']', false, 'onclick=" hikashopHandleCases(this);"');
        ?>
      </td>
    </tr>
  <?php }  ?>

i can see at the end of the code that the code is being called by a onclick.. i want an onload? this is the last piece of the puzzle! i think i will be doing a backflip when i get this working lol..

Thanks again nicholas.. hikashop will get every eCommerce project of mind..

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 2 months ago #26217

The begining of your code:
var choice= $c1;
function hikashopHandleCases(obj){

var doextra = false;
if(){


should be:
var doextra = false;
if(true){

if I understand what you want to do.

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 2 months ago #26220

<?php
/**
 * @package    HikaShop for Joomla!
 * @version    1.5.1
 * @author    hikashop.com
 * @copyright  (C) 2010-2011 HIKARI SOFTWARE. All rights reserved.
 * @license    http://www.hikashop.com/commercial_license.php
 */
defined('_JEXEC') or die('Restricted access');
$choice=0;
$choice = $_SESSION['choice'];
echo $choice;
?>
<?php
  $js = "
<!--
function hikashopHandleCases(obj){
var doextra = false;
   if(".$choice."'===0){
doextra =true;
    var hide = new Array();
    var show = new Array();
     if(".$choice."'==1){
      show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(".$choice."'==2){
       show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       show.push('esnnumber');
       show.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(".$choice."'==3){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     else if(".$choice."'==4){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     

  else if(obj.name=='data[order][numberchoice]'){
       var hide = new Array();  
       var show = new Array();  
       if(obj.id=='numberchoice_keepnumber'){  
       show.push('customtext_173_13_32_23');  
       show.push('accountname');  
       show.push('billingaddress');  
       show.push('phone_number');  
       show.push('carrier');  
       show.push('account_number');  
       show.push('pin');  
       show.push('ssn');        
}  
else if(obj.id=='numberchoice_newnumber'){  
       hide.push('customtext_173_13_32_23');  
       hide.push('accountname');  
       hide.push('billingaddress');  
       hide.push('phone_number');  
       hide.push('carrier');  
       hide.push('account_number');  
       hide.push('pin');  
       hide.push('ssn');  
}    
   }  
switchFields(show,hide);
if(doextra){
var keepnumber = document.getElementById('numberchoice_keepnumber');
if(keepnumber.checked){
hikashopHandleCases(keepnumber);
}
}


   
}




function switchFields(show,hide){
 for(var i=0;i<show.length;i++){
   var found = hikashopGetElementsByClass('hikashop_checkout_'+show[i]+'_line',document,'tr');
   for(var k=0; k<found.length;k++){
      found[k].style.display = '';
   }
 }
 for(var j=0;j<hide.length;j++){
  var found2 = hikashopGetElementsByClass('hikashop_checkout_'+hide[j]+'_line',document,'tr');
  for(var l=0; l<found2.length;l++){ found2[l].style.display = 'none'; }
   
 }
}

function hikashopGetElementsByClass( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = \" \"+searchClass+\" \";
  for(i=0,j=0; i<tags.length; i++) {
    var test = \" \" + tags[i].className + \" \";
    if (test.indexOf(tcl) != -1)
      el[j++] = tags[i];
  }
  return el;
}

do_nothing( function(){
  var elements = document.getElementsByName(\"data[order][user_choice]\");
  for(var i=0,j=0; i<elements.length; i++) {
   if(elements[i].checked){
     hikashopHandleCases(elements[i]);
   }
 }
  
});

-->
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($js);
  $type = $this->type;
  foreach($this->extraFields[$type] as $fieldName => $oneExtraField) {  $css='';
 if($fieldName!='user_choice'){
 $css = 'style="display:none;"';
}

  ?>
    <tr class="hikashop_checkout_<?php echo $fieldName;?>_line" <?php echo $css; ?>>
      <td class="key">
        <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
      </td>
      <td>
        <?php
            echo $this->fieldsClass->display($oneExtraField,$this->$type->$fieldName,'data['.$type.']['.$fieldName.']', false, 'onclick=" hikashopHandleCases(this);"');
        ?>
      </td>
    </tr>
  <?php }  ?>

this is what i got as of right now. The $choice is coming through just fine. tested it with an echo. the page just loads and nothing happens. No fields are displayed other than the one that i don't want to show.

any clues for me?

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26223

Hey Nicholas,
So i thought of a clever way to get the result i want but it's till not working as it should hopefully you can clarify it for me. i went back to the original code. everything is working fine. i wan to make 2 modifications to the code below.

(1) to hide the user_choice fields for good. by removing the exception from the display:none part of the code.
(2) to check the radio field for the fields to show via JS like this.

if(".$choice."!=0)
{
if(".$choice."==1){
var choice1 = document.getElementById('user_choice_activate_both');
choice1.checked=true;}

else if(".$choice."==2){
var choice2 = document.getElementById('user_choice_activate_plan_other_phone');
choice2.checked=true;}

else if(".$choice."==3){
var choice3 = document.getElementById('user_choice_activate_plan_iq_phone');
choice3.checked=true;}
else{}
}
else{}

This code is not working as it should for some reason. i am getting an error from firebug saying that choice 2 is null... how can i give it the obj of the radio field? i am stuck!! lol...


Thanks..

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 1 month ago #26238

That error means that you don't have any element with the id user_choice_activate_plan_other_phone in your HTML. Are you sure that the id name is correct ?

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26300

yes i am using the right id for all of them. here is the complete

<?php
/**
 * @package    HikaShop for Joomla!
 * @version    1.5.1
 * @author    hikashop.com
 * @copyright  (C) 2010-2011 HIKARI SOFTWARE. All rights reserved.
 * @license    http://www.hikashop.com/commercial_license.php
 */
defined('_JEXEC') or die('Restricted access');
$choice=0;
$choice = $_SESSION['choice'];
echo $choice;
?>

<?php
  $js = "
<!--


function hikashopHandleCases(obj){

var doextra = false;
   if(obj.name=='data[order][user_choice]'){
doextra =true;
    var hide = new Array();
    var show = new Array();
     if(obj.id=='user_choice_activate_both'){
      show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(obj.id=='user_choice_activate_plan_other_phone'){
       show.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       show.push('esnnumber');
       show.push('mobile_serial_lock_code');
       hide.push('iqaccount');
     }else if(obj.id=='user_choice_activate_plan_iq_phone'){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     else if(obj.id=='user_choice_activate_phone'){
       doextra = false;
       hide.push('numberchoice')
       hide.push('customtext_173_13_32_23');
       hide.push('accountname');
       hide.push('billingaddress');
       hide.push('phone_number');
       hide.push('carrier');
       hide.push('account_number');
       hide.push('pin');
       hide.push('ssn');
       hide.push('esnnumber');
       hide.push('mobile_serial_lock_code');
       show.push('iqaccount');
     }
     
     }

  else if(obj.name=='data[order][numberchoice]'){
       var hide = new Array();  
       var show = new Array();  
       if(obj.id=='numberchoice_keepnumber'){  
       show.push('customtext_173_13_32_23');  
       show.push('accountname');  
       show.push('billingaddress');  
       show.push('phone_number');  
       show.push('carrier');  
       show.push('account_number');  
       show.push('pin');  
       show.push('ssn');        
}  
else if(obj.id=='numberchoice_newnumber'){  
       hide.push('customtext_173_13_32_23');  
       hide.push('accountname');  
       hide.push('billingaddress');  
       hide.push('phone_number');  
       hide.push('carrier');  
       hide.push('account_number');  
       hide.push('pin');  
       hide.push('ssn');  
}    
   }  
switchFields(show,hide);
if(doextra){
var keepnumber = document.getElementById('numberchoice_keepnumber');
if(keepnumber.checked){
hikashopHandleCases(keepnumber);
}
}


   
}




function switchFields(show,hide){
 for(var i=0;i<show.length;i++){
   var found = hikashopGetElementsByClass('hikashop_checkout_'+show[i]+'_line',document,'tr');
   for(var k=0; k<found.length;k++){
      found[k].style.display = '';
   }
 }
 for(var j=0;j<hide.length;j++){
  var found2 = hikashopGetElementsByClass('hikashop_checkout_'+hide[j]+'_line',document,'tr');
  for(var l=0; l<found2.length;l++){ found2[l].style.display = 'none'; }
   
 }
}

function hikashopGetElementsByClass( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = \" \"+searchClass+\" \";
  for(i=0,j=0; i<tags.length; i++) {
    var test = \" \" + tags[i].className + \" \";
    if (test.indexOf(tcl) != -1)
      el[j++] = tags[i];
  }
  return el;
}

do_nothing( function(){
  var elements = document.getElementsByName(\"data[order][user_choice]\");
  for(var i=0,j=0; i<elements.length; i++) {

   if(elements[i].checked){
document.elements[1].checked = true;
     hikashopHandleCases(elements[i]);
   }
 }
  
});

-->

if(".$choice."!=0)
var elements = document.getElementsByName(\"data[order][user_choice]\");
{
if(".$choice."==1){
var choice1 = document.getElementById('user_choice_activate_both');
choice1.checked=true;}
 
else if(".$choice."==2){
var choice2 = document.getElementById('user_choice_activate_plan_other_phone');
choice2.checked=true;}  

else if(".$choice."==3){
var choice3 = document.getElementById('user_choice_activate_plan_iq_phone');
choice3.checked=true;}
else{}
}
";
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration($js);
  $type = $this->type;
  foreach($this->extraFields[$type] as $fieldName => $oneExtraField) {  $css='';
 if($fieldName!='fake'){
 $css = 'style="display:none;"';
}

  ?>
    <tr class="hikashop_checkout_<?php echo $fieldName;?>_line" <?php echo $css; ?>>
      <td class="key">
        <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
      </td>
      <td>
        <?php
            echo $this->fieldsClass->display($oneExtraField,$this->$type->$fieldName,'data['.$type.']['.$fieldName.']', false, 'onclick=" hikashopHandleCases(this);"');
        ?>
      </td>
    </tr>
  <?php }  


?>

here is the complete html code of the step 2 where it should all be working.
<fieldset class="input">
		<legend>Additional information</legend>
		
	2
    <table cellspacing="0" cellpadding="0" border="0" class="hikashop_contentpane"><tbody><tr style="display:none;" class="hikashop_checkout_user_choice_line">
      <td class="key">
        <label for="user_choice">I want to</label>      </td>
      <td>
        <input type="radio" onclick=" hikashopHandleCases(this);" id="user_choice_activate_both" value="activate_both" name="data[order][user_choice]"><label for="user_choice_activate_both">Activate iQ Phone and Plan.</label><input type="radio" onclick=" hikashopHandleCases(this);" id="user_choice_activate_plan_other_phone" value="activate_plan_other_phone" name="data[order][user_choice]"><label for="user_choice_activate_plan_other_phone">Activate iQ Plan on existing phone.</label><input type="radio" onclick=" hikashopHandleCases(this);" id="user_choice_activate_plan_iq_phone" value="activate_plan_iq_phone" name="data[order][user_choice]"><label for="user_choice_activate_plan_iq_phone">Upgrade iQ Plan only</label><input type="radio" onclick=" hikashopHandleCases(this);" id="user_choice_activate_phone" value="activate_phone" name="data[order][user_choice]"><label for="user_choice_activate_phone">Upgrade iQ Phone on existing plan</label> <span class="hikashop_field_required">*</span>      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_numberchoice_line">
      <td class="key">
        <label for="numberchoice">I would like</label>      </td>
      <td>
        <input type="radio" onclick=" hikashopHandleCases(this);" id="numberchoice_newnumber" value="newnumber" name="data[order][numberchoice]"><label for="numberchoice_newnumber">A new number</label><input type="radio" onclick=" hikashopHandleCases(this);" id="numberchoice_keepnumber" value="keepnumber" name="data[order][numberchoice]"><label for="numberchoice_keepnumber">To activate using my existing Phone number</label>      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_customtext_173_13_32_23_line">
      <td class="key">
        <label for="customtext_173_13_32_23">Keep Your Number</label>      </td>
      <td>
        To Keep Your Current Phone Number, Please provide information below. <br><a href="https://www.iqcellular.com/index.php/component/content/article/7-iq/28-activation-information" class="jcepopup" type="text/html" rel="">Help<span class="jcemediabox-zoom-link"></span></a>      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_mobile_serial_lock_code_line">
      <td class="key">
        <label for="mobile_serial_lock_code">MSL</label>      </td>
      <td>
        <input type="text" value="" name="data[order][mobile_serial_lock_code]" onclick=" hikashopHandleCases(this);" id="mobile_serial_lock_code" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_esnnumber_line">
      <td class="key">
        <label for="esnnumber">ESN</label>      </td>
      <td>
        <input type="text" value="" name="data[order][esnnumber]" onclick=" hikashopHandleCases(this);" id="esnnumber" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_phone_number_line">
      <td class="key">
        <label for="phone_number">Phone #</label>      </td>
      <td>
        <input type="text" value="" name="data[order][phone_number]" onclick=" hikashopHandleCases(this);" id="phone_number" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_carrier_line">
      <td class="key">
        <label for="carrier">Carrier</label>      </td>
      <td>
        <input type="text" value="" name="data[order][carrier]" onclick=" hikashopHandleCases(this);" id="carrier" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_account_number_line">
      <td class="key">
        <label for="account_number">Account #</label>      </td>
      <td>
        <input type="text" value="" name="data[order][account_number]" onclick=" hikashopHandleCases(this);" id="account_number" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_pin_line">
      <td class="key">
        <label for="pin">Pin #</label>      </td>
      <td>
        <input type="text" value="" name="data[order][pin]" onclick=" hikashopHandleCases(this);" id="pin" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_ssn_line">
      <td class="key">
        <label for="ssn">SSN #</label>      </td>
      <td>
        <input type="text" value="" name="data[order][ssn]" onclick=" hikashopHandleCases(this);" id="ssn" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_accountname_line">
      <td class="key">
        <label for="accountname">Account Name</label>      </td>
      <td>
        <input type="text" value="" name="data[order][accountname]" onclick=" hikashopHandleCases(this);" id="accountname" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_billingaddress_line">
      <td class="key">
        <label for="billingaddress">Billing Address</label>      </td>
      <td>
        <input type="text" value="Address, City, State, Zip" name="data[order][billingaddress]" onclick=" hikashopHandleCases(this);" id="billingaddress" class="inputbox">      </td>
    </tr>
      <tr style="display:none;" class="hikashop_checkout_iqaccount_line">
      <td class="key">
        <label for="iqaccount">iQ Account (Phone Number)</label>      </td>
      <td>
        <input type="text" value="" name="data[order][iqaccount]" onclick=" hikashopHandleCases(this);" id="iqaccount" class="inputbox">      </td>
    </tr>
  		</tbody></table>
	</fieldset>

i tried many different ways to get the raido obj in the var.

the only place i didn't get a error was using the code below. This is only way i got it to go through but again nothing was triggered to show.. would this have something to do with the fact that it's being trigger by a onclick? even if i get it to automatically select the radio button in the background will it trigger the rest of the functions?
do_nothing( function(){
  var elements = document.getElementsByName(\"data[order][user_choice]\");
  for(var i=0,j=0; i<elements.length; i++) {
   if(elements[i].checked){
document.elements[1].checked = true;
     hikashopHandleCases(elements[i]);
   }
 }
  
})

Thanks again

Last edit: 13 years 1 month ago by Rickhavoc.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 1 month ago #26321

Your js code is not correct.

First , the --> should be after your code, not before.
Second the line:
var elements = document.getElementsByName(\"data[order][user_choice]\");

should be remove from after the line:
if(".$choice."!=0)
Otherwise, the JS is not valid and the elements variable is not used after that anyway so there is no point in having that line there.

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26322

i made the changes firebug says

choice2 is null
step-2()step-2 (line 267)
[Break On This Error] choice2.checked=true;}

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 1 month ago #26343

If you just want to trigger the javascript function when the page is loaded, you need to add that code at the end of your JS (the cod ethat I made, not the modified version you made which doesn't work ):

do_nothing( function(){
var choice=0;
if(".$choice."==1){
var choice = document.getElementById('user_choice_activate_both');
}

else if(".$choice."==2){
var choice = document.getElementById('user_choice_activate_plan_other_phone');
}

else if(".$choice."==3){
var choice = document.getElementById('user_choice_activate_plan_iq_phone');
}
if(choice!=0) hikashopHandleCases(choice);

});

That will trigger the hikashopHandleCases with the correct object based on the php $choice variable.

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 1 month ago #26356

i could hug you right now!!


thanks you so much.. i am in debt to you...

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum