SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not reading the value of a secondary drop down option.

    I have a primary and secondary drop down that works fine, but for some reson the value coming out of the secondary drop down is always 0 and not the value of it.

    Code:
    <div style="position:relative; float:left; width:290px; height:30px; line-height:30px; padding-top:4px;">
    <select name="primarycause" id="opts" onchange="showForm()">
    <option value="0">Select Option</option>
    <option value="Asphyxia, Poison or Drowning">Asphyxia, Poison or Drowning</option>
    <option value="Contact with electricity">Contact with electricity</option>
    <option value="Service strike">Service strike</option>
    <option value="Contact with plant or machinery">Contact with plant or machinery</option>
    <option value="Contact with vehicle">Contact with vehicle</option>
    <option value="Exposure to Fire or Explosion">Exposure to Fire or Explosion</option>
    <option value="Exposure to Harmful substances">Exposure to Harmful substances</option>
    <option value="Fall from height">Fall from height</option>
    <option value="Handling lifting or carrying">Handling lifting or carrying</option>
    <option value="Moving or Falling object">Moving or Falling object</option>
    <option value="Natural causes">Natural causes</option>
    <option value="Physical Assault">Physical Assault</option>
    <option value="Slip or Trip">Slip or Trip</option>
    <option value="Trapped by something collapsing">Trapped by something collapsing</option>
    <option value="Exposure to physical agents">Exposure to physical agents</option>
    </select></div>
    <a name="rottcause" id="rottcause"></a>
    <div style="position:relative; float:right; width:250px; height:30px; line-height:30px; padding-top:4px;">
    <div id ="f1" style="display:none;">
    <select name="rottcause" onchange="showForm()" >
    <option value="0">Select Option</option>
    <option value="Asphyxia">Asphyxia</option>
    <option value="Poison">Poison</option>
    <option value="Drowning">Drowning</option>
    </select>
    </div>
    
    <div id ="f2" style="display:none;">
    <select name="rottcause" onchange="showForm()">
    <option value="0">Select Option</option>
    <option value="Permanent wire or supply">Permanent wire or supply</option>
    <option value="Temp wire or supply">Temp wire or supply</option>
    <option value="Tools or machinery">Tools or machinery</option>
    </select>
    </div>
    
    <div id ="f3" style="display:none;">
    <select name="rottcause" onchange="showForm()">
    <option value="0">Select Option</option>
    <option value="Electrical cable">Electrical cable</option>
    <option value="BT cable">BT cable</option>
    <option value="Comms cable">Comms cable</option>
    <option value="Water">Water</option>
    <option value="Gas">Gas</option>
    <option value="Other service">Other service</option>
    </select>
    </div>
    Controlled via

    Code:
    function showForm(){
    var selopt = document.getElementById("opts").value;
    if (selopt == 'Asphyxia, Poison or Drowning') {
    document.getElementById("f1").style.display="block";
    document.getElementById("f2").style.display="none";
    document.getElementById("f3").style.display="none";
    document.getElementById("f4").style.display="none";
    document.getElementById("f5").style.display="none";
    document.getElementById("f6").style.display="none";
    document.getElementById("f7").style.display="none";
    document.getElementById("f8").style.display="none";
    document.getElementById("f9").style.display="none";
    document.getElementById("f10").style.display="none";
    document.getElementById("f11").style.display="none";
    document.getElementById("f12").style.display="none";
    document.getElementById("f13").style.display="none";
    document.getElementById("f14").style.display="none";
    document.getElementById("f15").style.display="none";
    }
    if (selopt == 'Contact with electricity') {
    document.getElementById("f2").style.display="block";
    document.getElementById("f1").style.display="none";
    document.getElementById("f3").style.display="none";
    document.getElementById("f4").style.display="none";
    document.getElementById("f5").style.display="none";
    document.getElementById("f6").style.display="none";
    document.getElementById("f7").style.display="none";
    document.getElementById("f8").style.display="none";
    document.getElementById("f9").style.display="none";
    document.getElementById("f10").style.display="none";
    document.getElementById("f11").style.display="none";
    document.getElementById("f12").style.display="none";
    document.getElementById("f13").style.display="none";
    document.getElementById("f14").style.display="none";
    document.getElementById("f15").style.display="none";
    }
    if (selopt == 'Service strike') {
    document.getElementById("f3").style.display="block";
    document.getElementById("f1").style.display="none";
    document.getElementById("f2").style.display="none";
    document.getElementById("f4").style.display="none";
    document.getElementById("f5").style.display="none";
    document.getElementById("f6").style.display="none";
    document.getElementById("f7").style.display="none";
    document.getElementById("f8").style.display="none";
    document.getElementById("f9").style.display="none";
    document.getElementById("f10").style.display="none";
    document.getElementById("f11").style.display="none";
    document.getElementById("f12").style.display="none";
    document.getElementById("f13").style.display="none";
    document.getElementById("f14").style.display="none";
    document.getElementById("f15").style.display="none";
    }
    if (selopt == 'Contact with plant or machinery') {
    document.getElementById("f4").style.display="block";
    document.getElementById("f1").style.display="none";
    document.getElementById("f2").style.display="none";
    document.getElementById("f3").style.display="none";
    document.getElementById("f5").style.display="none";
    document.getElementById("f6").style.display="none";
    document.getElementById("f7").style.display="none";
    document.getElementById("f8").style.display="none";
    document.getElementById("f9").style.display="none";
    document.getElementById("f10").style.display="none";
    document.getElementById("f11").style.display="none";
    document.getElementById("f12").style.display="none";
    document.getElementById("f13").style.display="none";
    document.getElementById("f14").style.display="none";
    document.getElementById("f15").style.display="none";
    }
    But on the complete page when I try and draw the secondary value out it comes back with zero.

    Code:
    $primarycause= mysql_real_escape_string($_POST["primarycause"]);
    $primarycause1= mysql_real_escape_string($_POST["primarycause"]);
    $primarycause2 = mysql_real_escape_string($_POST["rottcause"]);
    
    //$primarycause = $primarycause1."~".$primarycause2;
    //echo $primarycause;
    So $primarycause1 is fine, but not $primarycauuse2 and cant work out the reason, as all seems fine

  2. #2
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    673
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Not 100% sure but I think var is depreciated so I'm not sure if your showForm function works. At least it doesn't when I tried to test it. Getting T-string error.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Drummin, can you expand a little on what you mean, as when I select the primary drop down the secondary does appear for the user to select an option, but on submit the value doesnt come out only the value 0.

    I also have a check placed on it to make sure it has been selected and that doesnt work either, so there something wrong with it.

    The area I'm working on it is behind closed doors, but i can forward details on if that helps.

    Thanks for getting back to me though

  4. #4
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK have been through it and tried to find the error, and basically when the secondary drop down appears which its does correctly, it will not recognise any of the values, what ever of the values you choose it doesnt see it, it stays at 0 value.

    Very odd, as the correct secondary appears, and you can physically select a value, but it doesnt work.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you think its because all the secondary drop downs have the same name:

    <select name="rottcause">

    And basically the value of another one set to zero is over riding the value of one that has been selected.

    Code:
    <div id ="f1" style="display:none;">
    <select name="rottcause">
    <option value="0">Select Option</option>
    <option value="Asphyxia">Asphyxia</option>
    <option value="Poison">Poison</option>
    <option value="Drowning">Drowning</option>
    </select>
    </div>
    
    <div id ="f2" style="display:none;">
    <select name="rottcause">
    <option value="0">Select Option</option>
    <option value="Permanent wire or supply">Permanent wire or supply</option>
    <option value="Temp wire or supply">Temp wire or supply</option>
    <option value="Tools or machinery">Tools or machinery</option>
    </select>
    </div>
    
    <div id ="f3" style="display:none;">
    <select name="rottcause">
    <option value="0">Select Option</option>
    <option value="Electrical cable">Electrical cable</option>
    <option value="BT cable">BT cable</option>
    <option value="Comms cable">Comms cable</option>
    <option value="Water">Water</option>
    <option value="Gas">Gas</option>
    <option value="Other service">Other service</option>
    </select>
    </div>
    If it is, how would you get around that, as they are meant to be hidden if not asked to be displayed bythe javascript.

    This is the first part of the jscript, and just realised this thread is probably better off in the jscript forum.

    Code:
    function showForm(){
    var selopt = document.getElementById("opts").value;
    if (selopt == 'Asphyxia, Poison or Drowning') {
    document.getElementById("f1").style.display="block";
    document.getElementById("f2").style.display="none";
    document.getElementById("f3").style.display="none";
    document.getElementById("f4").style.display="none";
    document.getElementById("f5").style.display="none";
    document.getElementById("f6").style.display="none";
    document.getElementById("f7").style.display="none";
    document.getElementById("f8").style.display="none";
    document.getElementById("f9").style.display="none";
    document.getElementById("f10").style.display="none";
    document.getElementById("f11").style.display="none";
    document.getElementById("f12").style.display="none";
    document.getElementById("f13").style.display="none";
    document.getElementById("f14").style.display="none";
    document.getElementById("f15").style.display="none";
    }

  6. #6
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Brazil
    Posts
    9
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i think this happen because, you have 3 fields with same name (rottcause), do a test try select the last selectbox and see if the right value come. after try change the names or by javascript disable the fields not selecteds by id.

  7. #7
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep looks like we both spot on with it...

    At least I know what it is now.

    Thanks

  8. #8
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok as a result of the above findings i got most of it sorted and am now back on the home page checking to see if the secondary drop down has been selected, but as it always is there is a problem, in that it doesnt recognise it again.

    So this is where I am at the mo:

    Code:
    <div id ="f1" style="display:none;">
    <select name="rottcause1">
    <option value="0">Select Option</option>
    <option value="Asphyxia">Asphyxia</option>
    <option value="Poison">Poison</option>
    <option value="Drowning">Drowning</option>
    </select>
    </div>
    
    <div id ="f2" style="display:none;">
    <select name="rottcause2">
    <option value="0">Select Option</option>
    <option value="Permanent wire or supply">Permanent wire or supply</option>
    <option value="Temp wire or supply">Temp wire or supply</option>
    <option value="Tools or machinery">Tools or machinery</option>
    </select>
    </div>
    
    <div id ="f3" style="display:none;">
    <select name="rottcause3">
    <option value="0">Select Option</option>
    <option value="Electrical cable">Electrical cable</option>
    <option value="BT cable">BT cable</option>
    <option value="Comms cable">Comms cable</option>
    <option value="Water">Water</option>
    <option value="Gas">Gas</option>
    <option value="Other service">Other service</option>
    </select>
    </div>
    And this is the change to the jscript that I thought would fix this bit.

    Code:
    function showForm(){
    var selopt = document.getElementById("opts").value;
    if (selopt == 'Asphyxia, Poison or Drowning') {
    document.getElementById("f1").style.display="block";
    document.getElementById("f2").disabled = true;
    document.getElementById("f3").disabled = true;
    document.getElementById("f4").disabled = true;
    document.getElementById("f5").disabled = true;
    document.getElementById("f6").disabled = true;
    document.getElementById("f7").disabled = true;
    document.getElementById("f8").disabled = true;
    document.getElementById("f9").disabled = true;
    document.getElementById("f10").disabled = true;
    document.getElementById("f11").disabled = true;
    document.getElementById("f12").disabled = true;
    document.getElementById("f13").disabled = true;
    document.getElementById("f14").disabled = true;
    document.getElementById("f15").disabled = true;
    }
    if (selopt == 'Contact with electricity') {
    document.getElementById("f2").style.display="block";
    document.getElementById("f1").disabled = true;
    document.getElementById("f3").disabled = true;
    document.getElementById("f4").disabled = true;
    document.getElementById("f5").disabled = true;
    document.getElementById("f6").disabled = true;
    document.getElementById("f7").disabled = true;
    document.getElementById("f8").disabled = true;
    document.getElementById("f9").disabled = true;
    document.getElementById("f10").disabled = true;
    document.getElementById("f11").disabled = true;
    document.getElementById("f12").disabled = true;
    document.getElementById("f13").disabled = true;
    document.getElementById("f14").disabled = true;
    document.getElementById("f15").disabled = true;
    }
    if (selopt == 'Service strike') {
    document.getElementById("f3").style.display="block";
    document.getElementById("f1").disabled = true;
    document.getElementById("f2").disabled = true;
    document.getElementById("f4").disabled = true;
    document.getElementById("f5").disabled = true;
    document.getElementById("f6").disabled = true;
    document.getElementById("f7").disabled = true;
    document.getElementById("f8").disabled = true;
    document.getElementById("f9").disabled = true;
    document.getElementById("f10").disabled = true;
    document.getElementById("f11").disabled = true;
    document.getElementById("f12").disabled = true;
    document.getElementById("f13").disabled = true;
    document.getElementById("f14").disabled = true;
    document.getElementById("f15").disabled = true;
    }
    if (selopt == 'Contact with plant or machinery') {
    document.getElementById("f4").style.display="block";
    document.getElementById("f1").disabled = true;
    document.getElementById("f2").disabled = true;
    document.getElementById("f3").disabled = true;
    document.getElementById("f5").disabled = true;
    document.getElementById("f6").disabled = true;
    document.getElementById("f7").disabled = true;
    document.getElementById("f8").disabled = true;
    document.getElementById("f9").disabled = true;
    document.getElementById("f10").disabled = true;
    document.getElementById("f11").disabled = true;
    document.getElementById("f12").disabled = true;
    document.getElementById("f13").disabled = true;
    document.getElementById("f14").disabled = true;
    document.getElementById("f15").disabled = true;
    }

  9. #9
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Brazil
    Posts
    9
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i think the best way to solve this is use ajax to load the options.

  10. #10
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi perdeu,

    Ye sorry i even posted the wrong info above, but basically all i need to do know is check that the drop down has been selected.

    Will have a look at the ajax option


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •