SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast ToolBox84's Avatar
    Join Date
    May 2012
    Location
    Glendale, CA. Los Angeles.
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Submit Button Help!!!

    I crated a form box just like the one on this site. http://www. progresspreferred .com/about_us.php

    The form on the left side "Get an Instant quote"

    Instead of the "Get a Quote" button i put the regular "Submit Form" button.

    <form action="" method="post" id="instant-quote"><table width="200" border="0">
    <tr>
    <td><span id="zip-code">
    <label for="zipCode"></label>
    <input type="text" name="zipCode" id="zipCode" tabindex="1" />
    <span class="textfieldRequiredMsg"><br />
    A value is required.</span></span></td>
    <td><label for="procuts"></label>
    <select name="procuts" id="procuts" tabindex="2">
    <option value="Auto" selected="selected">Auto</option>
    <option value="Trucks">Trucks</option>
    <option value="Home">Home</option>
    <option value="Contractors">Contractors</option>
    <option value="Business Owners">Business Owners</option>
    </select></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" id="submit" onclick="return next()" value="Continue" tabindex="3" /></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>

    NOW I want my visitors to select the insurance product (Auto, Home...) and click on the "submit" button and the submit button takes them to whatever option they chose on the drop down menu. Just the way it work on that website. How can this be done? What do I need to add in the code to make it work? If it is javascript can someone give me the code? I would really appreciate it.

    Thank you

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    To process a form like that, you need some kind of "server side" script, like PHP. You can Google something "PHP contact form" and you'll find a lot of code examples. (I'll move this to the PHP forum, anyhow.)
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast ToolBox84's Avatar
    Join Date
    May 2012
    Location
    Glendale, CA. Los Angeles.
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not it to process anything. All I want is when they select out it takes them to auto insurance page. Like a link to the submit button so it can take them to the auto page, then another link to the home insurance and the rest... It doesnt have to process anything just move me from location to location... I dont know if this can be done with javascript.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    1. Use JS (requires JS to be enabled)
    Code:
    <select onchange="window.location.href=this.options[this.selectedIndex].value">
    <option value="page1.php">Page 1</option>
    <option value="page2.php">Page 2</option>
    </select>
    2, Use PHP to submit the form and then use PHPs header() function.

    Where 'location' was the name of your variable -- which you have to
    validate prior to using as in the example below:

    PHP Code:

    // output absolutely nothing to the browser prior to doing this:

    if( something is true ){
    header('Location: ' $_POST['location'])
    exit();


  5. #5
    SitePoint Enthusiast ToolBox84's Avatar
    Join Date
    May 2012
    Location
    Glendale, CA. Los Angeles.
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    1. Use JS (requires JS to be enabled)
    Code:
    <select onchange="window.location.href=this.options[this.selectedIndex].value">
    <option value="page1.php">Page 1</option>
    <option value="page2.php">Page 2</option>
    </select>
    2, Use PHP to submit the form and then use PHPs header() function.

    Where 'location' was the name of your variable -- which you have to
    validate prior to using as in the example below:

    PHP Code:

    // output absolutely nothing to the browser prior to doing this:

    if( something is true ){
    header('Location: ' $_POST['location'])
    exit();

    I am not familiar with programing so php is hard for me to understand. I would want to do it with javascript code. have the users make the selection and when they click on the button it redirects them to the location they have selected. Can this be done with javascript? If yes would you please give me the code?

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following:
    HTML
    Code html4strict:
    <select name="page" id="page">
    <option value="page1.php">Page 1</option>
    <option value="page2.php">Page 2</option>
    </select>
    <input type="button" name="btncilck" id="btnclick" value="GO" onclick="redirect();" />

    JavaScript function redirect() would look like:
    Code javascript:
    function redirect(){
    var page = document.getElementById('page');
    document.location=page.options[page.selectedIndex].value;
    }
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,118
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    The problem with using JavaScript is that anyone who has it off (for whatever reason) won't be able to move from page to page. That's why it's better to let the server handle it.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  8. #8
    SitePoint Enthusiast ToolBox84's Avatar
    Join Date
    May 2012
    Location
    Glendale, CA. Los Angeles.
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    The problem with using JavaScript is that anyone who has it off (for whatever reason) won't be able to move from page to page. That's why it's better to let the server handle it.
    That is fine. Javascript will do just fine for me.

  9. #9
    SitePoint Member blogaddition's Avatar
    Join Date
    Sep 2012
    Location
    India
    Posts
    23
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Then the better Idea is, suppose you are having this form on about_us.php page. so write the following code on top of the about_us.php.

    <?php
    if(isset($_REQUEST['procuts']) && $_REQUEST['procuts'] != NULL){
    $page_redirect = $_REQUEST['procuts'];
    header("Location: $page_redirect");
    }
    ?>

    Now your form will be like below

    <form name="form" id="form" action="<?php $_SERVER['PHP_SELF'];?>">
    <select name="procuts" id="procuts" tabindex="2">
    <option value="auto.php" selected="selected">Auto</option>
    <option value="trucks.php">Trucks</option>
    <option value="home.php">Home</option>
    <option value="contractors.php">Contractors</option>
    <option value="business_owners.php">Business Owners</option>
    </select>
    <input type="submit" name="submit" value="submit" />
    </form>
    This will let you to do exactly whatever you want to do.


Tags for this Thread

Bookmarks

Posting Permissions

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