Hi everyone

I have a little problem that I'm sure someone here can help me with.

I have a web page with a text input field and a couple of submit button. The user would enter something in the text field and then click on one of the buttons. Each button opens a new page. But all of this is pretty standard coding, so I'm trying to do this a bit differently...

When the user first arrive at this page, the two button are not visible. The user then enters something, which is checked with PHP, using

if (isset($_POST['Submit'])) {
if ($_POST['Submit'] == "Yes" or "No") {
if (isset($_POST['sPostcode'])) $postcode = $_POST['sPostcode'];

Therefore, if the value of Submit is "Yes", then the postcode line is evaluated.

Then, a bit further down, there is this bit of code for the two buttons.

<?php
if ($postcode != "") {
print "<tr>";
print "<td colspan='2' align='left' valign='top' class='labelSect'><br>";
print "<center>Now select either the Left or Right button below</center>";
print "</td>";
print "</tr>";
}
?>

The above code is actually just a message telling the user that the two buttons are now available. Initially, this message isn't shown, but if the user actually clicks either button, the message is shown.

That isn't exactly how I wanted it to work, as I cannot hide the buttons, and the above code will only work if a button is pressed.

I think what I would like to know is, is there something, perhaps like JavaScript(?), that can tell if something is actually entered into a text input box?

Thanks
Terry

It is possible in javscript so here is a small sample, probably not the best sample but a sample nonetheless

<script type="text/javascript">
function theChecker() { if(document.getElementById('textin').value=="") 
{ document.getElementById('subm1').disabled=true;document.getElementById('subm2').disabled=true; } 
else 
{ document.getElementById('subm1').disabled=false;document.getElementById('subm2').disabled=false; } }
</script>
<input id='textin' type='text' onkeyup='theChecker();'><br>
<input id='subm1' type='submit' disabled='disabled' value='submit1'> &nbsp; <input id='subm2' type='submit' disabled='disabled' value='submit2'>

see also string.length to ensure the correct number of digits for a postcode

Hi almostbob

Thanks for such a quick reply. And, so far, it appears to be almost what I was looking for.

There is one thing that would make your solution perfect, although I don't think it is possible, and that for something to make the two buttons invisible instead of "greyed out".

Thanks again
Terry

try

document.getElementById('subm1').style.display='hidden' <!-- instead of line disabled-->
document.getElementById('subm1').style.display='block'

but .. disabled='disabled' is cross-browser friendly uses one line of code for all browsers
IE uses one dom, FF moz safari use a different dom so the show hide values are different, often requires complex scripts

<script type='text/javascript'><!--
function hideIt(elem) {
if(document.getElementById) { document.getElementById(elem).style.visibility='hidden';}
if(document.layers) {document.layers[elem].visibility='hide';} }
function showIt(elem) {
if(document.getElementById) {document.getElementById(elem).style.visibility='visible';}
if(document.layers) {document.layers[elem].visibility='show';} }
--></script>

more complicated <input value='' id='textin' onchange="showIt('subm1');showit('subm2');"> still no guarantees untested code

Thanks almostbob, but I couldn't get that to work properly. And the more I look at your first solution, the more I like it.

So I think I will stick with that.

Terry

<a href="productformaction.php?deleteproduct=<?php echo $seriol; ?>"><i class="fa fa-trash" style="color:red; float:left;"></i></a> </div>

what should i do to hide this delete button for all and show only to one user that is admin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.