javascript breaks when element not visible... :(

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • faif
    New Member
    • Sep 2007
    • 7

    #1

    javascript breaks when element not visible... :(

    Hello,

    I'm using a javascript function to pass the values of various form elements. The problem is that the script breaks when I'm trying to retrieve a value of an element that is not visible, because of category/subcategory dependency.

    The function is:
    [code="javascrip t"]
    <script language="JavaS cript">
    function reloadF(f)
    {
    var catV = document.getEle mentById('cat') ;
    var subcatV = document.getEle mentById('subca t');
    var priceV = document.getEle mentById('price ID'); // depends on category
    var priceRentV = document.getEle mentById('price RentID'); // depends on category

    location.href = 'file.php?catV= ' + catV.value + '&subcatV=' + subcatV.value + '&priceV=' + priceV.value + '&priceRentV= ' + priceRentV.valu e;
    </script>
    [/code]

    in the form:
    [code="html"]
    <select id="cat" onchange="reloa dF(this.form)" ...>
    <select id="subcat" onchange="reloa dF(this.form)" ...>

    if ($_GET['catV'] == 3)
    <input type="text" id="priceID" value="$_GET['priceV']" ...>

    if ($_GET['catV'] != 3)
    <input type="text" id="priceRentID " value="$_GET['priceRentV']" ...>
    [/code]

    Thank you.
  • faif
    New Member
    • Sep 2007
    • 7

    #2
    Originally posted by faif

    Found it, just after the post... :)
    I needed to use hidden elements, like:

    [code=html]
    if ($_GET['catV'] == 3)
    <input type="text" id="priceID" value="$_GET['priceV']" ...>
    else
    <input type="hidden" id="priceID" ...>

    [/code]

    Thank you.
    Thanks again. ............... ............... ......

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by faif
      Found it, just after the post... :)
      How many times does that happen? At least the :( became a :) !

      Comment

      Working...