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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Make a page refresh when a "Submit" button is clicked?

    I have this as the button for a voting form:

    Code:
    <input type="button" id="btn_vote" name="vote" value="Vote Now" onclick="if(selected) vote(); else alert(\'You need to pick an option\');" disabled=true />
    How do I make the page automatically refresh after the submit button has bee clicked? The results only show on refresh.

    Thanks
    Mike
    I've been making animations for my daughter. Tell me what you think!

    Pickles and the Bully
    Where are you Pickles!?!

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    change type="button" to type="submit"

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    change type="button" to type="submit"
    Thanks, but no - that didn't change anything. The page/form still does not reboot.
    I've been making animations for my daughter. Tell me what you think!

    Pickles and the Bully
    Where are you Pickles!?!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I think you need to show us the full <form> that contains that button along with the JS code for the vote() function.
    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.

  • #5
    Regular Coder
    Join Date
    Apr 2010
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Here is the snippet out of the PHP code for that page. Let me know if there are any bits extra you might need to see:

    Code:
    if (getCookie("vote_"+poll_id))
    {
        document.write( '<div class="whatdouthinkcontent"><?php echo $res['question'];?></div><div id="polls-head"><div id="polls-content"></div></div>'+
                        ' ');
    	loadResult(path_result + 'results.php', {id: <?php echo @$_GET['id'];?>});
    } else
    document.write(' '+
    
    '<div class="whatdouthinkcontent"><?php echo $res['question'];?></div>'+
    
    '<div id="whatdouthnkradiosection"><?php
    if(!@in_array(@$_GET['id'], @$_SESSION['voted_id'])) {
    	foreach( $options as $val) {
    		echo '<input name="radio" type="radio" class="radiobutton" onclick="selected=true; vote_btn_enabled(); temp_id = ', @$_GET['id'], "; temp_value = \\'", htmlentities( $val['name'] ),
    		"\\';\" >",
    		html_entity_decode( $val['name'] ),
    		'\n</a><br />\n';
    	}
    }
    ?></div>'+'<div id="votenowsection"><input type="submit" id="btn_vote" name="vote" value="Vote Now" class="votenow" onclick="if(selected) vote(); else alert(\'You need to pick an option\');" disabled=true /><a style="display:block;" href="javascript:;" onclick="viewResults();"> </a></div>'+
    ' '
    );

    Thanks!
    Mike
    I've been making animations for my daughter. Tell me what you think!

    Pickles and the Bully
    Where are you Pickles!?!

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Please don't show PHP code.

    Bring up the page in your browser.
    Click on the VIEW menu of your browser.
    Click on the SOURCE (or PAGE SOURCE) menu item.

    From the HTML *as the browser sees it* that you will now be looking at, copy/paste the relevant parts.

    Also, since these are <form> fields you are showing us, make sure you include everything from <form> to </form>, unless it's just irrelevant text descriptions, etc.
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    As an even better alternative, show us a live URL to look at, if possible.
    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.

  • #8
    New Coder
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should probably get in the habit of separating your JavaScript from your HTML. That would most likely make things significantly easier for you to type and lower your risk of making a mistake.

    Look into the <script> tag on W3 schools.


  •  

    Posting Permissions

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