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 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    118
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Form submit does not work

    the showUser function has ajax in it that calls a php file that accesses a db to perform some calculations.

    I wanted to use the clicked function to force required dropdowns to be selected but I cannot seem to get the submit button to do anything. It does nothing when you click it. Not sure how to proceed, have looked everywhere. If anyone has any advice I would really appreciate it.


    Code:
    <form id="forecastfilter" action="indexo_beats.php" method="get" onsubmit="clicked(this.value='yes')">
    
    <div class="fc">Date:</div>
    <select name="date" onchange="showUser(this.value)">
    <option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <option value="Date: Past Hour">Past hour</option>
    <option value="Date: Past week">Past week</option>
    <option value="Date: Past month">Past month</option>
    <option value="Date: Past year">Past year</option>
    </select>
    
    <br />
    <div class="fc">Wideouts:</div>
    <select name="wideouts" onchange="showUser(this.value)">
    <option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <option value="Wideouts: Higher">Revised Higher</option>
    <option value="Wideouts: Unchanged">Remains Unchanged</option>
    <option value="Wideouts: Lower">Revised Lower</option>
    </select>
    
    <br />
    <div class="fc">QBs:</div>
    <select name="qbs" onchange="showUser(this.value)">
    <option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <option value="QBs: beat">Above Analyst Estimates</option>
    <option value="QBs: inline">Inline with Analyst Estimates</option>
    <option value="QBs: miss">Below Analyst Estimates</option>
    </select>
    
    <br />
    <div class="fc">Football:</div>
    <select name="football" onchange="showUser(this.value)">
    <option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <option value="Football: beat">Above Analyst Estimates</option>
    <option value="Football: inline">Inline with Analyst Estimates</option>
    <option value="Football: miss">Below Analyst Estimates</option>
    </select>
    
    <br />
    <div class="fc">Sentiment:</div>
    <select name="sentiment" onchange="showUser(this.value)">
    <option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <option value="Sentiment: good">Good</option>
    <option value="Sentiment: neutral">Neutral</option>
    <option value="Sentiment: bad">Bad</option>
    </select>
    	<div class="searchbutton">
    	<input type="button" value="Search Draft" />
    	</div>
    </form>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,608
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    What "submit button"?? You don't have one. You have a button, but (a) it is not a submit button and (b) it has no onclick action specified so indeed it does nothing at all.

    Further, your onsubmit function for the <form> makes no sense.

    Code:
        onsubmit="clicked(this.value='yes')"
    The this in there refers to the <form> tag. A <form> tag does not *HAVE* a .value property. So that JavaScript would give an error. And an error in the JS means the <form> will then be submitted, no matter what.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    118
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post

    Further, your onsubmit function for the <form> makes no sense.

    Code:
        onsubmit="clicked(this.value='yes')"
    The this in there refers to the <form> tag. A <form> tag does not *HAVE* a .value property. So that JavaScript would give an error. And an error in the JS means the <form> will then be submitted, no matter what.
    I simply want to send the word "yes" to my function called clicked... wasn't sure how to do this. sorry confused

  • #4
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    118
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I am so damn confused.... Nothing is working

    BODY
    Code:
    <body>
    <form id="filter" action="index.php" method="get" onsubmit="clicked()">
    <div class="filtercaption">Date:</div>
    <select name="date" onchange="showUser(this.value)">
    <option value="">--</option>
    <option value="Date: Past Hour">Past hour</option>
    <option value="Date: Past week">Past week</option>
    <option value="Date: Past month">Past month</option>
    <option value="Date: Past year">Past year</option>
    </select>
    <input type="submit" value="Search Draft" />
    </form>
    HEADER, specifically the the clicked() function
    Code:
    function clicked()
    {
    xmlhttp.open("GET","getselection.php?q=clicked",true);
    xmlhttp.send();
    }
    getselection.php
    Code:
    <?php
    $q=$_GET["q"];
    $con = mysql_connect('localhost', 'username', 'password');
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("nameofdb", $con);
    $ip=$_SERVER['REMOTE_ADDR'];
    $sql="INSERT INTO counter (selection, ip) VALUES ('".$q."','".$ip."')";
    
    $result = mysql_query($sql);
    
    
    mysql_close($con);
    ?>


    All i want to do is put the word "clicked" into a mysql table when a user hits my submit button.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Why don't you just do the click tracking in indexo_beats.php which is the form action?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Regular Coder
    Join Date
    May 2011
    Location
    new york
    Posts
    118
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Why don't you just do the click tracking in indexo_beats.php which is the form action?
    I'll try this, ty

  • #7
    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 phpchick View Post
    Code:
    function clicked()
    {
    xmlhttp.open("GET","getselection.php?q=clicked",true);
    xmlhttp.send();
    }
    You're setting-up an asynchronous request them immediately dismissing the page. I would either use a synchronous request or return false and use the readystatechange handler to submit the form.


  •  

    Posting Permissions

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