Jump to content

Function not working


Go to solution Solved by XCalibre3,

Recommended Posts

Why isn't this working?

echo" <br><br><button name='submit' class = 'btn' id='btn' onclick='hideButton()'>Click to Verify Information</button>";

echo" <br><br><button name='submit' class = 'btn' id='btn' onclick='hideButton()'>Click to Verify Information</button>";

THen Function:

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

the button does disappear but then comes back after a blink.  So you can see if disappear.  I'n lost on why it doesn't just stay gone.  If you need more code just ask.  Thank you!

Link to comment
https://forums.phpfreaks.com/topic/316146-function-not-working/
Share on other sites

Since the <button> doesn't have a "type" attribute, the default behavior is to submit the form. That's likely why the page is flashing and the button is redisplayed. You could try the following:

echo" <br><br><button name='submit' type='button' class = 'btn' id='btn' onclick='hideButton()'>Click to Verify Information</button>";

More information about the <button> tag can be found here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

 

With that said, I'm guessing the button is supposed to submit the form given it's named "submit". So you may need to tweak the JavaScript to submit the form if the verification process doesn't find any issues.

  • Like 1
3 hours ago, cyberRobot said:

Since the <button> doesn't have a "type" attribute, the default behavior is to submit the form. That's likely why the page is flashing and the button is redisplayed. You could try the following:

echo" <br><br><button name='submit' type='button' class = 'btn' id='btn' onclick='hideButton()'>Click to Verify Information</button>";

More information about the <button> tag can be found here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

 

With that said, I'm guessing the button is supposed to submit the form given it's named "submit". So you may need to tweak the JavaScript to submit the form if the verification process doesn't find any issues.

This does nothing at all.  I click the button and it just stays there as if I never clicked it.

  • Solution
3 hours ago, cyberRobot said:

Since the <button> doesn't have a "type" attribute, the default behavior is to submit the form. That's likely why the page is flashing and the button is redisplayed. You could try the following:

echo" <br><br><button name='submit' type='button' class = 'btn' id='btn' onclick='hideButton()'>Click to Verify Information</button>";

 

15 hours ago, maxxd said:

What does "comes back after a blink" mean? First thing I notice is that you're missing a closing brace in your function.

 

This resolved the issue.  Thank you both!  It worked by putting the closing brace and changing type.  Thanks much!  I don't know who to mark as solution.

Edited by XCalibre3
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.