Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Positioning an Item

Status
Not open for further replies.

slr22

MIS
Jun 26, 2002
80
US
Is there a way to tell a button, textbox, etc to be in an exact location. For example, if you say I want that word to be 12 spaces over and 3 spaces down. Is there an attribute of a button or something that I can tell it where to be placed? Currectly I have a form and I just put the stuff in a table to align it, however I need one thing to be placed in a specific location. The way that it is set up right now when I click on a button the table shifts because something larger appears.

Thanks.
 
Use the style property of the button or object.

Example:

<Button style=&quot;position:absolute;top:50;left:125&quot;>Next</button>

Use Position and the &quot;absolute&quot; keywoard and then specifiy your top and left positions.

Simple!

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
That works, I've never done a button that way. The only problem is, is there a way to show and hide this type of button? I need to hide this button when the user clicks the button.
 
Why yes there is...

<button style=&quot;display:none&quot;> To hide

<button style=&quot;display:inline&quot;> To show &quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
No I mean, when the user clicks this button can I hide it. For example currectly this is how I handle it

Sub button1_onclick()
button1.hide
listbox.show
end sub

Sub listbox_onchange()
button1.show
listbox.hide
end sub

Is there a way that when the user clicks on this button I can hide it? I'm sure there has to be, I'm just not sure how.

Thanks for all the help you are giving me!
 
You'll need some javascript code:

If your button already has an onclick event associated with it then you can include the following code in the function that is called.

Place in your onclick function:
*make sure you give your button an id.. Example <button ID=&quot;YourID&quot; >Next</button>

var objBtn=document.getElementById(&quot;YourButtonID&quot;);
objBtn.style.display=&quot;none&quot; //to hide
objBtn.style.display=&quot;display&quot; //to show

If your button does not have a function associated with the onclick event then you can do the following.

<button ID=&quot;YourID&quot; onclick=&quot;this.style.display='none'&quot;>Next</button>





&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Ok I see you using VBScript...

Change code in your onclick to:

dim objBtn
set objBtn=document.getElementById(&quot;YourButtonID&quot;);
objBtn.style.display=&quot;none&quot; //to hide
objBtn.style.display=&quot;display&quot; //to show
&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
I must be missing something. I keep getting an error. This is what my code looks like:

Sub button1_onclick()
dim objBtn
set objBtn=document.getElementById(&quot;button1&quot;)
objBtn.style.display=&quot;none&quot;
end sub


<button id=&quot;button1&quot; onclick=&quot;btnbutton1_onclick()&quot; style=&quot;position:absolute;top:50;left:125&quot;>Next</button>


I am a little confused on the difference with the javascript and the vbscript with your

<button ID=&quot;YourID&quot; onclick=&quot;this.style.display='none'&quot;>Next</button>

Should I have this.style.display='none' in place of btnbutton1_onclick()

I see the button but it give me an error saying object expected.

I have some mix of javascript and vbscript in my application however it doesn't like it when I call the textboxes and listboxes when I use the javascript so I need to stay with the vbscript if possible.

When I click on the button I need to be able to hide the button and show my listbox.


Thanks.
 
Also, when I use your code in the javascript when I click on another button or refresh the page it brings the button I just hide back. Why does it do that? Is it because I don't have it set up correctly?
 
Yes,

Ok for your vbscript code first:

button id=&quot;button1&quot; onclick=&quot;btnbutton1_onclick()&quot; style=&quot;position:absolute;top:50;left:125&quot;>Next</button>

Your calling a different onclick event.

For your 2nd question:

If you refresh the page the button will come back, because it's default display is &quot;inline&quot;. clicking on other buttons should not affect your hidden button unless they do something to the page like submitting or refreshing.

Instead of the vbscript code you code just use the below code:

<button ID=&quot;YourID&quot; Name=&quot;YourID&quot; onclick=&quot;this.style.display='none'&quot;>Next</button>

Make sure you have both ID and Name defined

&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
Ok. I can get the button to hide, however how do I get it to show a listbox. All the button does is hide the button. How do I call an onclick event. For example if I have the button:

<button ID=&quot;button2&quot; Name=&quot;button2&quot; onclick=&quot;this.style.display='none'&quot; style=&quot;position:absolute;top:59;left:150&quot;> Next2</button>

but I also want to show a listbox when this button is hidden, how do I do that too?

I tried the following code:

<button ID=&quot;button2&quot; Name=&quot;button2&quot; onclick=&quot;button2_onclick()='none'&quot; style=&quot;position:absolute;top:59;left:150&quot;> Next2</button>

Sub button2_onclick()
dim objBtn
set objBtn=document.getElementById(&quot;button2&quot;)
objBtn.style.display=&quot;none&quot;
LstRidgeVent.show
end sub

however that gives me an error. Can I do both (hide the button and show a listbox all in one click using this type of button)?
 
ok, dude...

First you need to take a tutorial on Javascript and vbscript, so you can get some basic understanding of how to do things.

To show the list box, you must first have a list box on your webpage but set its style.display=&quot;none&quot;. Don't forget to give it an ID=&quot;YourListBox&quot;

Here is a modification to your button click. Try to understand how it is to access your objects.

Sub button2_onclick()
dim objBtn, objLst
set objBtn=document.getElementById(&quot;button2&quot;)
objBtn.style.display=&quot;none&quot;

set objLst=document.getElementById(&quot;YourListBox&quot;)
objLst.style.display=&quot;inline&quot;
end sub


&quot;did you just say Minkey?, yes that's what I said.&quot;

MrGreed
 
First of all, I'm not a &quot;dude&quot;.

Second, I am still a little confused by some of your syntax. If I specify something in the &quot;onclick=&quot; parameter, such as &quot;this.style.display='inline'&quot;, then the regular onclick event does not fire (i.e. my button2_onclick subroutine does not get executed.) So I don't really understand how you use the display property in the onclick event and do other processing at the same time.

Nonetheless, I decided to go a different route with this. Thanks for your help.

Sandy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top