Click to See Complete Forum and Search --> : hiding a button - onchange()


tripwater
11-25-2003, 04:07 PM
I have a button that allows a user to post a form and start their time logging.

On this screen they can create a task and post it for themselves as well as for others. However I want to hide the Post & Start Time button if they select a developer that is not them.

I do not want them to be able to start the time on someone else's task.

I still have another post button to just post the task and not start the time. I am new to Javascript so don't laugh at the approach. I thought I could just change the input type of the button to hidden onchange if the logged in did not match the selected. I am using php BTW

Here is what I have


<script>
function hide()
{
if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")
{
document.addtask.starttime.type = 'hidden';
}
}

</script>

<form name=addtask>
<select name=developers onchange=javascript:hide();>

<option>

</select>

####This is what I want to hide if the logged in sess var does not match the selected id in developers (they are both integers)####
<input type=button name=starttime value=submit>

</form>



I tried to keep it simple and left out all the other code. Hope it is enough. Thank you ahead of time for any help.

gil davis
11-25-2003, 04:19 PM
I have a stupid question.

Assuming you already know who the developer is, why do you give him a select box anyway?

It would be fairly easy to gate the function of the button so that if the select has changed the button will not work.

Also, I would think that hiding the button would require you to show it again if the user changes the select back to the correct position.

It would not surprise me to find out that you could hide the button in IE by changing its visibility property. I know for sure that t would not work on NS 4.

gil davis
11-25-2003, 04:24 PM
Here is the IE solution:
<head>
<script>
function hide() {
if (document.f1.b1.style.visibility == "visible")
{document.f1.b1.style.visibility ="hidden";}
else
{document.f1.b1.style.visibility ="visible";}
}
</script>
</head>
<body>
<form name="f1" onsubmit="return false">
<select onchange="hide()">
<option>one
<option>two
<option>three
<option>four
<option>five
<option>six
</select>
<input name="b1" type="button" value="submit" style="visibility: visible">
</form>
</body>

tripwater
11-25-2003, 04:25 PM
Thanks for the reply. I need the select list there so they can still add a task for a different developer and hit post but I do not want them to be able to hit the post and start time button I have available which automatically posts the task and starts their time if they are not the user they selected.

I assumed the code I used in my function

if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")


would take care of both if they are not, and if they are the logged in user.

I would just need to hide if the statement was true and display it if false.

Am I incorrect?

Thanks

tripwater
11-25-2003, 04:28 PM
sort of confused by your last post.

I do not see where the function is dependant upon the developer list selection being different than the logged in user.

tripwater
11-25-2003, 04:53 PM
Right now if I call my function:



function hide()
{
if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")
alert('hello');

else
alert('world');
}


onchange it works fine.

I just need to know how to hide my post&start time button which is
<input type=image name=starttime src=../image>

Thanks again

gil davis
11-25-2003, 09:07 PM
Originally posted by tripwater
sort of confused by your last post.

I do not see where the function is dependant upon the developer list selection being different than the logged in user. It isn't. It was an example of how to hide the button. The rest of the exercise is left to the student.

gil davis
11-25-2003, 09:11 PM
Originally posted by tripwater
function hide()
{
if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")
alert('hello');

else
alert('world');
}

...
<input type=image name=starttime src=../image>
function hide() {
if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")
{document.addtask.starttime.style.visibility = "hidden";}
else
{document.addtask.starttime.style.visibility = "visible";}
}

tripwater
11-26-2003, 07:48 AM
Thanks for the reply.

However it did not seem to work in Mozilla and I went to IE and received this

error : 'document.addtask.starttime.style' is null or not an object


Here is how I am calling my function


<select name=developers onchange=javascript:hide();>


</select>

gil davis
11-26-2003, 12:28 PM
it did not seem to work in MozillaI never said it would. I specifically said IE.
error : 'document.addtask.starttime.style' is null or not an objectOk, I suppose you need to declare the style in the button before you try to use it.
<input type=image name=starttime src=../image>Try:
<input type="image" name="starttime" src="../image" style="visibility: visible">
BTW, you need to put quotes around HTML properties if you want to be cross-browser compatible. W3 recommendations require them.

Also, it is incorrect to specify the "javascript:" URL in an event handler. The only place it is necessary is in the HREF of a link, where it really is expecting a URL.
<select name="developers" onchange="hide()">

tripwater
12-02-2003, 09:09 AM
Thank you for the help. Sorry it took me so long to get back I have been out of town...Got Married.



I made the changes BTW thanks for the info on the javascript: call in the href.


I am still getting the same IE error and the image does not hide onchange.


here is what I currently have:



<js>

function hide()
{
if (document.addtask.developers.value != ".$HTTP_SESSION_VARS["devid"].")
document.addtask.starttime.style.visibility = \"hidden\";

else
document.addtask.starttime.style.visibility = \"visible\";
}

</js>



<form name=\"addtask\" method=\"post\" action=\"../mypage\">

<select name=\"developers\" onchange=\"hide();\">

<option>

</select>



<input name=\"starttime\" type=image src=\"../images/post&start.gif\" style=\"visibility:visible\">

</form>





I left out the unecessary stuff and just gave you the code I am working on. Thanks again.