after onChange - clear input fields

Discussion in 'JavaScript' started by lostsouler, Oct 21, 2010.

  1. #1
    Hi, Im newbie in JS, but I tried code myself.
    I have a problem, because if I select another option in dropdown the input fields doesnt clear, because when is submit the form, not chosed - hided values are sent.

    onChange -> rozmertext -> clear: rozm_textx and rozm_texty

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script type="text/javascript">
    function showtext(c) {
    if(c=="leskly") {
    document.getElementById("lesk").style.display="block";
    }
    else {
    document.getElementById("lesk").style.display="none";
    }
    
    if(c=="matny") {
    document.getElementById("mat").style.display="block";
    }
    else {
    document.getElementById("mat").style.display="none";
    }
    if(c=="iny") {
    document.getElementById("iny").style.display="block";
    }
    else {
    document.getElementById("iny").style.display="none";
    }
    }
    
    function rozmertext(a) {
    if(a=="iny") {
    document.getElementById("rozm_text").style.display="block";
    
    }
    else {
    
    document.getElementById("rozm_text").style.display="none";
    
    }
    }
    function showlamin(b) {
    if(b=="l_mat") {
    document.getElementById("lamin").style.display="block";
    
    }
    else {
    document.getElementById("lamin").style.display="none";
    }
    }
    
      function clearFields() {
     document.getElementByName('rozm_textx').value = "";
    }
    </script>
    
    </head>
    
    <body>
    <form action="proces.php" method="post">
    <label>Rozmery:</label><select name="rozmery" id="rozmery" onChange="rozmertext(this.value);clearFields(this)">
      <option>A3:29,7 x 42cm</option>
      <option>A4:21 x 29,7cm</option>
      <option>A5:14 x 21cm</option>
      <option>DL:9 x 21cm</option>
      <option value="iny">iný</option>
    </select>
    <div id="rozm_text" style="display:none;float:right;">
    <label style="display:inline;">Šírka(cm):</label><input name="rozm_textx" type="text" style="margin-left:10px;" />
    <label style="display:inline;">Výška(cm):</label><input name="rozm_texty" type="text"  style="margin-left:10px;" /></div>
    <br />
    <label>Farebnosť:</label><select name="farebnost" id="farebnost">
      <option>4+4</option>
      <option>4+1</option>
      <option>4+0</option>
      <option>1+1</option>
      <option>1+0</option>
    </select><br />
    <label>Papier:</label><select name="papier" id="papier" onchange="showtext(this.value)">
      <option value="">vyber</option>
      <option value="leskly">lesklý</option>
      <option value="matny">matný</option>
      <option value="iny">iný</option>
    </select>
    <select name="p_leskly" id="lesk" style="display:none;margin-left:10px;float:right;">
      <option>115 g/m2</option>
      <option>130 g/m2</option>
      <option>160 g/m2</option>
      <option>200 g/m2</option>
      <option>250 g/m2</option>
      <option>280 g/m2</option>
    </select>
    <select name="p_matny" id="mat" style="display:none;margin-left:10px;float:right;">
      <option>80 g/m2</option>
      <option>90 g/m2</option>
      <option>130 g/m2</option>
      <option>160 g/m2</option>
      <option>200 g/m2</option>
      <option>250 g/m2</option>
      <option>280 g/m2</option>
    </select>
    <select name="p_iny" id="iny" style="display:none;margin-left:10px;float:right;">
      <option>potom</option>
    </select>
    
    <br />
    <label>Náklad:</label><input name="naklad" type="text" />
    <label style="display:inline;margin-left:15px;">Počet druhov:</label><input name="pocetdruhov" type="text"  />
    <br />
    <label>Lomy:</label><input name="lomy" type="text" /><br />
    <label>Laminácia:</label><select name="laminacia" onChange="showlamin(this.value)">
      <option>žiadna</option>
      <option value="l_mat">1+0 mat</option>
      <option value="l_mat">1+1 mat</option>
      <option>1+0 lesk</option>
      <option>1+1 lesk</option>
    </select>
    <div id="lamin" style="display:none;margin-left:15px;"> <label >Parcialny lak:</label><select name="parcialnylak"  style="display:inline;">
      <option>žiadny</option>
      <option>1+1 lesklý</option>
      <option>1+0 lesklý</option>
    </select></div>
    <p>
      <input type="submit" name="button" id="button" value="Submit" />
    </p>
    
    
    </body>
    </html>
    
    HTML:
    <?php
    $rozmery = $_POST['rozmery'];
    $rozm_textx = $_POST['rozm_textx'];
    $rozm_texty = $_POST['rozm_texty'];
    $farebnost = $_POST['farebnost'];
    $papier = $_POST['papier'];
    $p_leskly = $_POST['p_leskly'];
    $p_matny = $_POST['p_matny'];
    $p_iny = $_POST['p_iny'];
    $naklad = $_POST['naklad'];
    $pocetdruhov = $_POST['pocetdruhov'];
    $lomy = $_POST['lomy'];
    $laminacia = $_POST['laminacia'];
    $parcialnylak = $_POST['parcialnylak'];
    
    echo "Rozmery: ".$rozmery ."  Iné rozmery (SxV): ".$rozm_textx." x ".$rozm_texty."<br />";
    echo "Farebnost: ".$farebnost ."<br />";
    echo "Papier: ".$papier; echo $p_leskly; echo $p_matny; echo $p_iny;"<br />";
    echo "Naklad: ".$naklad ."<br />";
    echo "Pocet druhov: ".$pocetdruhov ."<br />";
    echo "Lomy: ".$lomy ."<br />";
    echo "Laminacia: ".$laminacia; echo $parcialnylak;"<br />";
    
    ?>
    
    PHP:
    What do I wrong?

    Thx for the answer.
     
    lostsouler, Oct 21, 2010 IP
  2. kai555

    kai555 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi

    Im guessing it's because you call the method with a parameter clearFields(this) (this is the parameter)

    but your method doesn't take any parameters.

    try removing the this.
     
    kai555, Oct 25, 2010 IP