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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Location
    Portland, OR
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript setting value of hidden variable

    I really thought this would work, a user goes to a page, selects a value from a select box then clicks a link to run a report using that hidden variable as a parameter. I am attempting to place the value in the URL to pass it. I'm sure the javascript is working, and maybe it's the HTML I've messed up - not sure.
    Here is the javascript (the alert does return the correct value):
    Code:
    function OnChangeDay() {
    	//assign the day id to the hidden variable $day
    	x=eval(document.getElementById("day_loc_id_select").value)
    	
    	if(x) {	
            document.getElementById("test_day_id").value=x;
        } else {
            document.getElementById("test_day_id").value=0;
        }
    	// test
    	alert(document.getElementById("test_day_id").value)  
    }
    Here is the calling HTML:
    Code:
    <input type="hidden" name="test_day" id="test_day_id" value="">
    
     <select name="day_loc_id" id="day_loc_id_select"  
                  onchange="OnChangeDay()"> 
     <option></option>
            <?= form_options($day_loc_options) ?>
    </select>
    And here is the HTML that should send the value, but I get day= (nothing)
    Code:
    <a href='/depts/edoptions/excel_extract.php?ex=2&day=<? echo $test_day ?>'>SLIP Data to Excel</a>
    Can anyone point out where I've messed up?
    Thanks

  • #2
    Regular Coder
    Join Date
    Sep 2010
    Location
    Virginia
    Posts
    112
    Thanks
    11
    Thanked 7 Times in 7 Posts
    This works like you would want it...you only need javascript.

    Code:
    <?php
    
    function form_options()
    {
    	echo '<option value= "hola">hola </option>';
    	echo '<option value= "como estas">como estas </option>';
    }
    
    ?>
    
    <!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 OnChangeDay() {
    	//assign the day id to the hidden variable $day
    	x= document.getElementById("day_loc_id_select").value;
    	document.getElementById("test_day_id").value = x;
    	alert(document.getElementById("test_day_id").value);
    	
    	var url = '/depts/edoptions/excel_extract.php?ex=2&day=';
    	var hidden = document.getElementById("test_day_id").value;
    	url += hidden;
    	
    	var a_link = document.getElementById("link");
    	a_link.setAttribute("href", url);
    	
    }
    </script>
    </head>
    
    <body>
    
    <input type="hidden" name="test_day" id="test_day_id" value="">
    
     <select name="day_loc_id" id="day_loc_id_select" onchange="OnChangeDay();" value="hello"> 
    <?php form_options(); ?>
    </select>
    <a id="link" href="">SLIP Data to Excel</a>
    
    </body>
    </html>
    Last edited by Afro_Programmer; 12-01-2010 at 06:46 PM.


  •  

    Posting Permissions

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