Jump to content

Recommended Posts

No offense, but with over 4,000 posts I would have thought you would have learned to be more descriptive  :D

 

You didn't say what would trigger this action or if you are talking about a dropdown or checkboxes or what.  In short though, you would wrap your swap code in an if that checks the value of the control (assuming a dropdown):

 

var e = document.getElementById("idOfControl");
var v = e.options[e.selectedIndex].value;

if(v == "pick 3") {
   // do swap code
}

 

As far as I can tell this is a JavaScript question.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/228729-form-help/#findComment-1179241
Share on other sites

That doesn't make sense.  PHP will only see the value of a form control when you submit the form to the PHP script.  So then you would just have a PHP if that determines whether to show the DIV or the hidden DIV:

 

if($_POST['myFormField'] == 'pick 3') {
   //echo div
} else {
   //echo hidden div
}

Link to comment
https://forums.phpfreaks.com/topic/228729-form-help/#findComment-1179249
Share on other sites

i know this works if i use it as a check box.

 

function MM_findObj(n, d) { //v4.01
    var p,i,x;  
    if(!d) {
        d=document; 
    }    
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) {
        x=d.all[n]; 
    }    
    for (i=0;!x&&i<d.forms.length;i++) {
        x=d.forms[i][n];
    }    
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) {
        x=MM_findObj(n,d.layers[i].document);
    }    
    if(!x && d.getElementById) {
        x=d.getElementById(n); 
    }    
    return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
    var obj = MM_findObj(objName);
    if (obj && (theProp.indexOf("style.")==-1 || obj.style)) {
        if (theValue == true || theValue == false) {
            eval("obj."+theProp+"="+theValue);
        } else { 
            eval("obj."+theProp+"='"+theValue+"'");
        }    
    }
}

function swap(name, mark,theProp){
    if (mark) {
        var theValue = 'inline';
    } else {
        var theValue = 'none';
    }
    var obj = MM_findObj(name);
    if (obj && (theProp.indexOf("style.")==-1 || obj.style)) {
        eval("obj."+theProp+"='"+theValue+"'");
    }
}

Link to comment
https://forums.phpfreaks.com/topic/228729-form-help/#findComment-1179272
Share on other sites

Ugh, Dreamweaver code.  Yuck.

 

I'm still not 100% certain how you're expecting PHP to do this.  It would take either a page refresh or Ajax to have PHP determine which div to show.  Remember, when your page is rendered on the screen, PHP is done running.  It doesn't have interactive capabilities like JavaScript.

Link to comment
https://forums.phpfreaks.com/topic/228729-form-help/#findComment-1179277
Share on other sites

Which is what AbraCadaver described....

 

Are you wanting to do this in PHP because you don't know JavaScript?  I ask because I'm getting a strong "I don't know JavaScript, so I'm going to throw a bunch of JS scripts at the wall and pray one of them sticks" vibe from this whole thing.  To flesh out AC's example, it should be as simple as:

 

var selectElem = document.getElementById('mySelect');

selectElem.onchange = function(){
   var value = this.options[this.selectedIndex].value;

   if(value === /* something */){
      // toggle div
   }
}

 

Assuming you're using an actual HTML select element/drop down.

Link to comment
https://forums.phpfreaks.com/topic/228729-form-help/#findComment-1179282
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.