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 5 of 5
  1. #1
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts

    After submit, refresh page automatically

    I'm not a javascript expert ...

    Here is what I'm trying to do.

    I have a form with two radio buttons (On and Off).
    When either radio button is clicked, I submit the form to a URL.
    I then need to automatically refresh the page after the form is submitted.

    This is what I have so far. It currently does submit the form, that works OK (by the way, it is submitting it to itself .. it's a PHP script). But then I need the page to refresh for updating some other things that PHP does.

    Code:
    <form id="myForm1" action="<?=$_SERVER['php_self']?>" method="post">
    			OUTPUT 7:
    			<input type="radio" id="but7" name="v" value="71" onClick="javascript: submit()"  onMouseOver="style.cursor='hand'"> ON
    			<input type="radio" id="but7" name="v" value="70" onClick="javascript: submit()"  onMouseOver="style.cursor='hand'"> OFF
    		</form>

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    most likely you can edit the submit function to return true, or simply remove it the onclick function altogether and submit the form as you normally would.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,932
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Wow, I’m wondering about the outdated code there? cursor: hand? That hasn’t been valid CSS ever and was only needed for some ancient version of Netscape if I recall correctly. It’s called “pointer” nowadays — and by the way: this can be done with CSS, with a simple line like
    Code:
    input[type=radio]:hover {cursor: pointer;}
    As to the submit functionality: don’t use onclick on form controls, use onchange. Also get rid of the javascript: crap in the event handler. It’s only JavaScript that can be executed there, no need to announce that before. On submitting the form the page should refresh automatically, actually, so I don’t know what the problem is?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Thanks ... I'll work on it. It is old code I just copied and I was using it.

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,932
    Thanks
    6
    Thanked 1,041 Times in 1,014 Posts
    Oh and by the way: the name and id attributes must have unique values each, i. e. there can’t be two elements with the same name/ID in one document. Well, name is kind of an exception in that you can store the name in an array, i. e. give the names square brackets (like name="example[]" on multiple elements) and you can read it out with PHP like example[1] etc.


  •  

    Posting Permissions

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