Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: submit button need alert if value not select rather then send to blank page

  1. #1
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default submit button need alert if value not select rather then send to blank page

    I have a product page that sends to a product detail page, The detail page also has all other products from the catagory.. The problem is when they land on the page it shows their selected product but in order for the information to pass to the cart they need to select the product first, even though they are already on the page (because there are other produts there) at present if they do not choose their product and just hit select it sends them to a blank page. i need to to prompt and say " please select design first)

    this is the form

    PHP Code:
    <form id="FormName" action="" method="get" name="FormName">
                <table>
                  <tr valign="middle">
                    <td width="30" height="40" class="meduimTXT">1.</td>
                    <td width="190" align="left"><div align="left">
                      <select name="ID" class="text" id="selectName">
                        <option value="Select Design">Select Design</option>
                        <?php
                                            mysql_select_db
    ($database_beau$beau);
                                            
    $query sprintf("SELECT * FROM beauProd WHERE CatID = '%s'"GetSQLValueString($row_Recordset1['CatID'], "int"));
                                            
    $results mysql_query($query$beau) or die(mysql_error());
                                            
    $productsInCategory = array();
                                            while(
    $row mysql_fetch_array($results)){
                                                      
    $productsInCategory[] = $row['ID'];
                                                      
    ?>
                        <option value="<?php echo $row['ID']; ?>"><?php echo $row['name']; ?></option>
                        <?php
                                            
    }
                                            
    ?>
                      </select>
                    </div></td>
                    <td width="190" align="left"><input type="image" src="../images/select design.gif" border="0" name="button" id="button" value="select new design" /></td>
                  </tr>
                </table>
              </form>


    thanks in advance

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Wouldn't it be easier to simply deactivate the button until they have selected a product?

    What you could do in answer to your question, is set up a JavaScript to alert onclick if no product is selected using a simple if/else.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #3
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    ideally yes deactivate the button until an option is selected.

    how would i go about do that?
    thanks

  4. #4
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    well in order to actually deactivate the button, you should use:
    Code:
    function disable(){
    document.getElementById('button').disabled = true; 
    }
    so simply check if one of the products is selected and then trigger the function if it's not.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  5. #5
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I have tried the following but am sure its wrong

    Code:
    <script type='text/javascript'>
    function disable(){
    document.getElementById('button').disabled = true; 
    }
    </script>
    <form id="button" method="post" action="" onclick="function()">
        <p>
            <select id="ad_type" name="ad_type">
                <option value="" selected="selected">Select premium ad type</option>
                <option value="<?php echo TYPE_USER;?>">Featured Agent</option>
            </select>
    Last edited by keyboard; 09-29-2012 at 06:18 AM. Reason: Format: Code Tags

  6. #6
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thats wrong on my behalf not your. Thanks in advance

  7. #7
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thinking about it i would need the alert with an if/else statement

  8. #8
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    you may want something like:
    Code:
    <script type='text/javascript'>
    function disable(){
    if(ID.value == 'Select Design'){
    document.getElementById('button').disabled = true; 
    }
    }
    </script>
    <form id="button" method="post" action="" onclick="disable()">
    <p>
    <select id="ad_type" name="ad_type">
    <option value="" selected="selected">Select premium ad type</option>
    <option value="<?php echo TYPE_USER;?>">Featured Agent</option>
    </select>
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  9. #9
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thanks for that, but the process of the form is they select a design (then have to submit that in order to give the values of that design) then choose the size below then send to cart so the alert would be better.

  10. #10
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Code:
    <script type='text/javascript'>
    function disable(){
    if(ID.value == 'Select Design'){
    alert('please select an option');
    }
    }
    </script>
    <form id="button" method="post" action="" onclick="disable()">
    <p>
    <select id="ad_type" name="ad_type">
    <option value="" selected="selected">Select premium ad type</option>
    <option value="<?php echo TYPE_USER;?>">Featured Agent</option>
    </select>
    Last edited by keyboard; 09-29-2012 at 06:18 AM. Reason: Format: Code Tags
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

Similar Threads

  1. Replies: 0
    Last Post: 09-16-2012, 05:17 PM
  2. Convert submit button to Onchange submit
    By stand247 in forum JavaScript
    Replies: 3
    Last Post: 10-25-2011, 09:01 AM
  3. Replies: 0
    Last Post: 02-17-2011, 02:42 AM
  4. Replies: 6
    Last Post: 03-05-2009, 07:18 AM
  5. Chained select display blank list
    By Fabien in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 05-15-2008, 06:31 PM

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
  •