Help with select tag and href in HTML

Discussion in 'HTML & Website Design' started by rohan191, Sep 19, 2012.

  1. #1
    Hello,
    I am designing a website and needed some guidance.
    I have three drop-down boxes. Year, Month and contractor. I have a link used to download a file from server when a user clicks it.

    This is the HTML Code


    <h1>Please select the period and a contractor</h1>
    <h3>Contractor: <select id="cont" name="cont" >
    <option value="TEIL">TEIL(PMC)</option>
    <option value="LTLSTK">L&amp;T LSTK</option>
    <option value="TL">THERMAX</option>
    <option value="GTPL">GTPL</option>
    <option value="VA">VA TECH</option>
    <option value="VISHAL">VISHAL</option>
    <option value="BOC">BOC</option>
    <option value="GDMECH">GDCL MECH</option>
    <option value="GDCIVIL">GDCL CIVIL</option>
    <option value="LTENI">L&amp;T ENI</option>
    <option value="DOSH">DOSHION</option>
    <option value="HDOL">HDOL</option>
    <option value="AIROIL">AIROIL</option>
    <option value="IVRCL">IVRCL</option>
    <option value="LT">LIBRATECH</option>
    </select> </h3>
    <h3>Year: <select id="year" name="year">
    <option value="2010">2010</option>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    </select></h3>
    <h3>Month: <select id="month" name="month">
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>
    <option value="11">November</option>
    <option value="12">December</option>
    </select></h3>
    <p><a href=(value of year)/(value of month)/(Value ofcont).pdf">Click Here to fetch Record</a></p>

    the folder structure in my server is Year/Month/Contractor.pdf.

    I want my href to change dynamically as the user selects a value from dropdown. how can i do it??
     
    Solved! View solution.
    rohan191, Sep 19, 2012 IP
  2. #2
    You could do it with Javascript, but that can be deactivated by the client...

    So just use PHP (or ASP) if available

    Just make a form

    
        <form method="post" action="go.php">
            <h3>Contractor:</h3> 
            <select id="cont" name="cont" >
                <option value="TEIL">TEIL(PMC)</option>
                <option value="LTLSTK">L&amp;T LSTK</option>
                <option value="TL">THERMAX</option>
                <option value="GTPL">GTPL</option>
                <option value="VA">VA TECH</option>
                <option value="VISHAL">VISHAL</option>
                <option value="BOC">BOC</option>
                <option value="GDMECH">GDCL MECH</option>
                <option value="GDCIVIL">GDCL CIVIL</option>
                <option value="LTENI">L&amp;T ENI</option>
                <option value="DOSH">DOSHION</option>
                <option value="HDOL">HDOL</option>
                <option value="AIROIL">AIROIL</option>
                <option value="IVRCL">IVRCL</option>
                <option value="LT">LIBRATECH</option>
            </select> 
            <h3>Year:</h3>
            <select id="year" name="year">
                <option value="2010">2010</option>
                <option value="2011">2011</option>
                <option value="2012">2012</option>
                <option value="2013">2013</option>
            </select>
            <h3>Month:</h3>
            <select id="month" name="month">
                <option value="1">January</option>
                <option value="2">February</option>
                <option value="3">March</option>
                <option value="4">April</option>
                <option value="5">May</option>
                <option value="6">June</option>
                <option value="7">July</option>
                <option value="8">August</option>
                <option value="9">September</option>
                <option value="10">October</option>
                <option value="11">November</option>
                <option value="12">December</option>
            </select>
            <input type="submit" name="GO" value="Click here to fetch Record"/>
        </form>
    
    HTML:
    now that the form is ready, create a new site called go.php (you can name that site whatever you like, but you also have to change the form action accordingly)
    On go.php, paste this
    
        <?php
        if(isset($_POST["GO"]))
        {
            header( "Location: localhost/".$_POST['cont']."/".$_POST['year']."/".$_POST['month'].".pdf");
        }
        ?>
    
    PHP:

    Note: This was thrown together very quickly. It is ugly as hell, has almost no checks and not really secure, but it works. :p


    EDIT: Just realized that the link in the header() function should be changed to your domain
     
    Last edited: Sep 20, 2012
    GMF, Sep 20, 2012 IP
    matt_62 likes this.
  3. rohan191

    rohan191 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Works like a charm!!! Thanks a lot for your prompt reply!!
     
    rohan191, Sep 20, 2012 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Also, what makes a LABEL and a SELECT a level 3 heading? (skipping right past level two) -- They are NOT the start of subsections of the page. Same can probably be said of the H1 which should likely be a LEGEND with all those form tags inside a FIELDSET.
     
    deathshadow, Sep 20, 2012 IP