Jump to content

trying to hide a button


XCalibre1
Go to solution Solved by Strider64,

Recommended Posts

This is so easy, but I have no clue why absolutely nothing works.  i've tried php, javascript, jquery and NOTHING is working.  For two hours now..... please someone help.  This was my last attempt to  hide the submit button when I press it.

<?php
echo" <div id = 'btn'>";
echo" <input type='submit' name='submit' id='btn' value='Submit' />";
echo" </div>";
echo" </form>";
?>

<script>
function hideButton(){
document.getElementById('btn').style.display= 'none';
}
</script>

See, that seems so simple, and it does work when I do the online examples, but it just won't work with me grrrr lol.

 

I have also tried using

<?php
echo '<p><input type="submit" name="submitted" id="send" value="Send" onclick="this.style.display='none';"></p>';
?>

using it this way of course with how I've written the form:

echo" <input type='submit' name='submit' id='submit' value='Submit' onclick='this.style.display='none'; />'";

 

Edited by XCalibre1
Link to comment
Share on other sites

40 minutes ago, XCalibre1 said:

See, that seems so simple, and it does work when I do the online examples, but it just won't work with me grrrr lol

You have id="btn" twice in that code, which is invalid.  ID's must be unique across the elements.  You also never actually call your hideButton function anywhere.  You need to apply it to some sort of event, such as the onclick of the button, if you want to have it run.

41 minutes ago, XCalibre1 said:

I have also tried using

This has a PHP syntax error due to the single-quotes around none, you need to escape them using a backslash.

43 minutes ago, XCalibre1 said:

I've written the form:

This version has a HTML syntax error because of the single quotes as well, as the end up closing the attribute early.  Your onclick attribute value is just this.style.display=, which is invalid javascript.

 

Link to comment
Share on other sites

24 minutes ago, kicken said:

 

This has a PHP syntax error due to the single-quotes around none, you need to escape them using a backslash.

 

This totally throws my whole format off, so won't work.  It takes me to all the components all to the left of the screen and whenI click submit, it takes me back to the regular format with the submit button, which doesn't do anything when you click it, as it should hide, but doesn't.  Maybe I wrote that code wrong? 

echo" <input type='submit' name='submit' id='submit' value='Submit' onclick='this.style.display=\"none\">";
Link to comment
Share on other sites

Well, this will disable the submit button, which is fine, I would rather have it hidden, but the issue is that it doesn't enter the information in the database and show the reservation number. UGHHHHH

echo"<button type='submit' id='submitbutton' onclick=\"document.getElementById('submitbutton').disabled = true\">Confirm Reservation</button>";

 

Link to comment
Share on other sites

  • Solution
8 hours ago, XCalibre1 said:

Well, this will disable the submit button, which is fine, I would rather have it hidden, but the issue is that it doesn't enter the information in the database and show the reservation number. UGHHHHH

echo"<button type='submit' id='submitbutton' onclick=\"document.getElementById('submitbutton').disabled = true\">Confirm Reservation</button>";

 

Like requinix says you should show the full code as it sounds more than hiding a submit button.

For example:

    /* Success function utilizing FETCH */
    const sendUISuccess = function (result) {
        //console.log('Result', result);
        if (result) {
            document.querySelector('#recaptcha').style.display = "none";
            submit.style.display = "none";
            document.querySelector('.pen').setAttribute('src', 'assets/images/target.png');
            //messageSuccess.style.display = "block";
            document.querySelectorAll('form > *').forEach(function (a) {
                a.disabled = true;
            });
        }
    };


// Function to handle errors when sending data to the database
    const sendUIError = function (error) {
        console.log("Database Table did not load", error);
    };

// Function to handle errors when saving data to the database
    const handleSaveErrors = function (response) {
        if (!response.ok) {
            throw new Error(`Save request failed with status ${response.status}: ${response.statusText}`);
        }
        return response.json();
    };

// Function to save the data to the database
    const saveDataToDatabase = (url, onSuccess, onError, data) => {
        fetch(url, {
            method: 'POST',
            body: JSON.stringify(data)
        })
            .then(response => handleSaveErrors(response))
            .then(data => onSuccess(data))
            .catch(error => onError(error));
    };

This is a portion of my JavaScript that uses Fetch to get a response back after a user sends the message. It hides the submit button, but verifies the message was sent and a few other things.

Edited by Strider64
Link to comment
Share on other sites

Seems odd to me that you want to hide a button that is submitting a form and your php script could do the hiding before the client is refreshed from the php processing.   This form goes away when you click on the button so why are you worrying about hiding it?

Link to comment
Share on other sites

6 hours ago, ginerjm said:

Seems odd to me that you want to hide a button that is submitting a form and your php script could do the hiding before the client is refreshed from the php processing.   This form goes away when you click on the button so why are you worrying about hiding it?

To prevent accidental repeated submissions of the form. Look around the internet and you'll see this "disable on click" paradigm everywhere.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.