Jump to content

hidden input


ilikephp

Recommended Posts

Do you really need to show/hide a second submit button? Your example code would seem to indicate you only need to change the value of the current submit button. Anyway the code below will show/hide the second submit button:

<html>
<head>
<script type="text/javascript">

function checkFields()
{
    if (document.getElementById('field1').value!='' &&
        document.getElementById('field2').value!='' &&
        document.getElementById('field3').value!='')
    {
        document.getElementById('submit2').style.visibility='visible';
    }
    else
    {
        document.getElementById('submit2').style.visibility='hidden';
    }
    return;
}

</script>
</head>
<body>

Field 1: <input type="text" name="field1" id="field1" onkeyup="checkFields();" /><br />
Field 2: <input type="text" name="field2" id="field2" onkeyup="checkFields();" /><br />
Field 3: <input type="text" name="field3" id="field3" onkeyup="checkFields();" /><br />

<input type="submit" name="submit" id="Submit" value="submit" />
<input type="submit" name="submit2" id="Submit" value="1" style="visibility:hidden;" />

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/158273-hidden-input/#findComment-834844
Share on other sites

Once you click submit the page is submitted and will reload. You could have the buttin show as soon as you click submit, but it will only display for a fraction of a second before the page reloads. I think you need to clearly explain what you are trying to accomplish.

Link to comment
https://forums.phpfreaks.com/topic/158273-hidden-input/#findComment-835928
Share on other sites

I have a registration form:

when I fill in all the fields, I need to click on the send button so all the fields will be checked for validation;

if all the fields are correct, the submit button will appear and a new page will be opened when I click on the submit button.

 

I need this submit button to be appeared if there are no errors. I put it as hidden, how to let it be visible? Thx...

Link to comment
https://forums.phpfreaks.com/topic/158273-hidden-input/#findComment-835965
Share on other sites

OK, so the first button really isn't a submit button at all!

 

In this situation you don't want to use two "submit" buttons anyway. If you had simply stated your objective in the beginnign we wouldn't have wasted this time.

 

If you want to do JavaScript validation you simply need to create an onsubmit event that will perform the validation and send the form if validation passes and if validation fails halt the fiorm submission and display the errors.

 

You just need to create a javascript function to perform the valiaftion and return true if there are no errors and return false if there are errors. Then in the FORM tab put an onsubmit trigger like this

<form name="theform" onsubmit="return validate();">

Link to comment
https://forums.phpfreaks.com/topic/158273-hidden-input/#findComment-836023
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.