Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem reloading the page

    i am new to JS and need help in solving my code that's not reloading the page to download subcat list from db when you select the cat list? Any help is appreciable:

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by shashikala View Post
    Any help is appreciable
    So is the need to show your code before anyone can help.

    Your <select>'s onchange handler could look something like this:
    Code:
    <select onchange="sendQuery(this, 'myParameter' )">
    
    ............
    <script type="text/javascript">
    
    function sendQuery( box, param )
    {
     var url = location.href.split( '?' )[ 0 ]; /* Remove any existing querystring */
    
     location.href = url + '?' + param + "=" + box.value + '&randVal=' + new Date().getTime();
    }
    
    </script>
    Where 'myParameter' is the parameter you're sending in the querystring.


  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks for the code:

    here is the code;
    <HTML>
    <HEAD>
    <STYLE type="test/css"></STYLE>
    <SCRIPT type="text/javascript">
    function reload(form) {
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <TABLE style="font-family:Verdhana New;font-size:12px; font-weight:normal" width="300" border="0" align="center" cellpadding="2"% cellspacing="1">
    <h3 align="center">Expense form</h3></br>
    <FORM action=" " method="post"><Font face="Verdana">
    <TR>
    <TD align="center">Amount: <Input type="text" name="amount" size="10"/></TD>
    </TR>
    <TR>
    <TD align="center">Month: <Input type="text" name="month" size="10"/></TD>
    </TR>
    <TR>
    <TD align="center">
    <?php
    $query1=mysql_query("SELECT DISTINCT category, cat_id FROM category order by category");
    //for second drop down list to check if category is selected
    if(isset($cat) and strlen($cat) >'0'){
    $query=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory");
    }
    else{
    $query=mysql_query("SELECT DISTINCT subcategory, subcat_id FROM subcategory order by subcategory");
    }
    //end of query of subcategory dropdown list box
    echo "<form method=post name=f1>";
    //starting of first drop down list
    echo "Category: " ."<select name='cat' onchange=\"reload (this.form)\">;
    <option value=''>Select one</option>";
    while($result1 = mysql_fetch_array($query1)) {
    if($result1['cat_id']==@$cat){
    echo "<option selected value='$result1[cat_id]'>$result1[category]</option>"."</br>";
    }
    else{
    echo "<option value='$result1[cat_id]'>$result1[category]</option>";
    }
    }
    echo "</select>" ."</br>";
    //End of first drop down list
    //Starting of second drop down list
    echo "</br>" ."Subcategory: " ."<select name='subcat'><option value=''>Select one</option>";
    while($result = mysql_fetch_array($query)) {
    if($result['subcat_id']==@$cat){
    echo "<option selected value='$result[subcat_id]'>$result[subcategory]</option>"."<BR>";
    }
    else{
    echo "<option value='$result[subcat_id]'>$result[subcategory]</option>";
    }
    }
    echo "</select>" ."</br>";
    //End of second drop down list
    ?>

    thanks again for looking into this....


  •  

    Posting Permissions

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