SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disable form button on submit, reenable it on radio button change?

    OK guys...

    I've got a CMS that I'm working on. It uses iframes to allow a member to preview their post before being submitted. This part of the CMS has a text field, two radio buttons (preview and post) and the submit button.

    I want to disable the submit button when they click it. The problem I'm thinking I will have is that if they do decide to preview the post first (I don't) the button won't be "live" for them to use.

    So, I've got two possible answers.

    1) Disable to form button on submit, then reenable it when the user changes the radio button.

    2) Only disable to submit button if the post radio button is checked.

    I think that 2 is a better method but I'm not sure how the code would look, but let me take a try.

    Code:
    <script type="javascript">
    <!--
    function submitOnce() {
    if (this.previewPost.post = "YES") {
    	this.elements['submit'].disabled=true;
    }
    -->
    </script>
    
    <form name="postNews" method="post" action="" onsubmit="submitOnce();">
    	<span class="formItemTitle">preview:</span>
    	<input type="radio" value="preview" name="previewPost" checked="checked">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	<span class="formItemTitle">post:</span>
    	<input type="radio" value="post" name="previewPost">
    	<input type="submit" name="submit" value="send this off...">
    </form>
    Tried that but it doesn't work. Gave me an error. Can anyone help me out?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're close...
    Code:
    onsubmit="submitOnce(this);"
    
    function submitOnce(f) {
    if (f.previewPost['post'].checked) {
    	f.elements['submit'].disabled=true;
    }
    That *should* do it
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope...throws an error on the FORM tag using the code below:

    PHP Code:
    <html>
    <
    head>
    <
    title> new document </title>

    <
    script type="javascript">
    <!--
    function 
    submitOnce(f) {
    if (
    f.previewPost['post'].checked) {
        
    f.elements['submit'].disabled=true;
    }
    -->
    </script>

    </head>
    <body>
    <form name="postNews" method="post" action="" onsubmit="submitOnce(this);">
        <span class="formItemTitle">preview:</span>
        <input type="radio" value="preview" name="previewPost" checked="checked">     
        <span class="formItemTitle">post:</span>
        <input type="radio" value="post" name="previewPost">
        <input type="submit" name="submit" value="send this off...">
    </form>
    </body>
    </html> 
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes


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
  •